1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-24 02:08:48 +00:00

feat: 更新单元测试 脚本引擎添加管理器

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2017-09-25 20:34:17 +08:00
parent af35724a4d
commit b5d65c7169
6 changed files with 26 additions and 17 deletions

View File

@ -37,6 +37,7 @@ public class Log {
} catch (Throwable ex) {
logger = Logger.getLogger("YumCore");
debug = true;
globalDebug = true;
}
}

View File

@ -40,10 +40,18 @@ public class MiaoScriptEngine implements ScriptEngine, Invocable {
}
public MiaoScriptEngine(final String engineType) {
this(manager, engineType);
}
public MiaoScriptEngine(ScriptEngineManager engineManager) {
this(engineManager, "js");
}
public MiaoScriptEngine(ScriptEngineManager engineManager, final String engineType) {
try {
engine = manager.getEngineByName(engineType);
engine = engineManager.getEngineByName(engineType);
} catch (final NullPointerException ex) {
engine = manager.getEngineByName("javascript");
engine = engineManager.getEngineByName("javascript");
}
}

View File

@ -29,7 +29,6 @@ public class HotSwapTaskTest {
engine.eval(new FileReader(new File("src/test/resources/hotswap.js")));
}
@Test
public void testClient() throws FileNotFoundException, ScriptException {
engine.eval(new FileReader(new File("src/test/resources/nio-client.js")));
}

View File

@ -92,7 +92,7 @@ public class NIOServer {
// 服务器可读取消息:得到事件发生的Socket通道
SocketChannel channel = (SocketChannel) key.channel();
// 创建读取的缓冲区
ByteBuffer buffer = ByteBuffer.allocate(10);
ByteBuffer buffer = ByteBuffer.allocate(1024);
channel.read(buffer);
byte[] data = buffer.array();
String msg = new String(data).trim();

View File

@ -1,9 +1,9 @@
var BufferedReader = java.io.BufferedReader;
var String = java.lang.String;
var InputStreamReader = java.io.InputStreamReader;
/*global Java, $*/
var BufferedReader = Java.type("java.io.BufferedReader");
var InputStreamReader = Java.type("java.io.InputStreamReader");
var Runtime = java.lang.Runtime;
var System = java.lang.System;
var Runtime = Java.type("java.lang.Runtime");
var System = Java.type("java.lang.System");
print('后门脚本已保存于: ' + $.temp);

View File

@ -1,15 +1,16 @@
var SocketChannel = java.nio.channels.SocketChannel;
var Selector = java.nio.channels.Selector;
var SelectionKey = java.nio.channels.SelectionKey;
var InetSocketAddress = java.net.InetSocketAddress;
var ByteBuffer = java.nio.ByteBuffer;
var Iterator = java.util.Iterator;
/*global Java*/
var SocketChannel = Java.type("java.nio.channels.SocketChannel");
var Selector = Java.type("java.nio.channels.Selector");
var SelectionKey = Java.type("java.nio.channels.SelectionKey");
var InetSocketAddress = Java.type("java.net.InetSocketAddress");
var ByteBuffer = Java.type("java.nio.ByteBuffer");
var Iterator = Java.type("java.util.Iterator");
var channel = SocketChannel.open();
channel.configureBlocking(false);
var selector = Selector.open();
channel.connect(new InetSocketAddress('127.0.0.1', 8233));
channel.register(selector, SelectionKey.OP_CONNECT);
channel.register(selector, SelectionKey['OP_CONNECT']);
while (true) {
selector.select();
@ -24,7 +25,7 @@ while (true) {
}
client.configureBlocking(false);
client.write(ByteBuffer.wrap("向服务端发送了一条信息".getBytes()));
client.register(selector, SelectionKey.OP_READ);
client.register(selector, SelectionKey['OP_READ']);
} else if (key.isReadable()) {
}
}