> getOnlineRemoteAddress(Serializable groupid);
+
+ //返回sessionid, null表示连接不合法或异常,默认实现是request.getSessionid(false),通常需要重写该方法
+ public Serializable onOpen(final HttpRequest request);
+
+
+ //创建groupid, null表示异常, 必须实现该方法, 通常为用户ID为groupid
+ /* protected abstract */ Serializable createGroupid();
+
+ //标记为@WebSocketBinary才需要重写此方法
+ default void onRead(AsyncConnection channel) {
+ }
+
+ default void onConnected() {
+ }
+
+ //接收文本消息响应事件,可能会接收到文本消息需要重写该方法
+ default void onMessage(String text) {
+ }
+
+ default void onPing(byte[] bytes) {
+ }
+
+ default void onPong(byte[] bytes) {
+ }
+
+ //接收二进制消息响应事件,可能会接收到二进制消息需要重写该方法
+ default void onMessage(byte[] bytes) {
+ }
+
+ default void onFragment(String text, boolean last) {
+ }
+
+ default void onFragment(byte[] bytes, boolean last) {
+ }
+
+ default void onClose(int code, String reason) {
+ }
+}
diff --git a/test/org/redkale/test/net/UploadTestServlet.java b/test/org/redkale/test/net/UploadTestServlet.java
new file mode 100644
index 000000000..dfc918877
--- /dev/null
+++ b/test/org/redkale/test/net/UploadTestServlet.java
@@ -0,0 +1,50 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.net;
+
+import org.redkale.net.http.HttpServlet;
+import org.redkale.net.http.MultiPart;
+import org.redkale.net.http.HttpRequest;
+import org.redkale.net.http.HttpResponse;
+import java.io.*;
+
+/**
+ *
+ * @author zhangjx
+ */
+//@WebServlet({"/uploadtest/form", "/uploadtest/send"})
+public class UploadTestServlet extends HttpServlet {
+
+ @Override
+ public void execute(HttpRequest request, HttpResponse response) throws IOException {
+ if (request.getRequestURI().contains("/uploadtest/send")) {
+ send(request, response);
+ } else {
+ form(request, response);
+ }
+ }
+
+ public void form(HttpRequest req, HttpResponse resp) throws IOException {
+ resp.setContentType("text/html");
+ resp.finish(
+ ""
+ + ""
+ + "");
+ }
+
+ public void send(HttpRequest req, HttpResponse resp) throws IOException {
+ for (MultiPart entry : req.multiParts()) {
+ entry.skip();
+ System.out.println(entry);
+ }
+ System.exit(0);
+ }
+}
diff --git a/test/org/redkale/test/service/Person.java b/test/org/redkale/test/service/Person.java
new file mode 100644
index 000000000..b0ed01586
--- /dev/null
+++ b/test/org/redkale/test/service/Person.java
@@ -0,0 +1,32 @@
+package org.redkale.test.service;
+
+import java.io.Serializable;
+
+public class Person implements Serializable {
+
+ private byte[] b = new byte[1024 * 2];
+
+ private String name;
+
+ @Override
+ public String toString() {
+ return "{name=" + name + ", b =" + (b == null ? "null" : "[length=" + b.length + "]") + "}";
+ }
+
+ public byte[] getB() {
+ return b;
+ }
+
+ public void setB(byte[] b) {
+ this.b = b;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
diff --git a/test/org/redkale/test/service/TestBean.java b/test/org/redkale/test/service/TestBean.java
new file mode 100644
index 000000000..4f7729d6e
--- /dev/null
+++ b/test/org/redkale/test/service/TestBean.java
@@ -0,0 +1,14 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.service;
+
+/**
+ *
+ * @author zhangjx
+ */
+public class TestBean {
+
+}
diff --git a/test/org/redkale/test/sncp/SncpTest.java b/test/org/redkale/test/sncp/SncpTest.java
new file mode 100644
index 000000000..b029a2bef
--- /dev/null
+++ b/test/org/redkale/test/sncp/SncpTest.java
@@ -0,0 +1,210 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.sncp;
+
+import org.redkale.net.sncp.Sncp;
+import org.redkale.convert.bson.BsonFactory;
+import org.redkale.net.Transport;
+import org.redkale.service.Service;
+import org.redkale.net.sncp.SncpServer;
+import org.redkale.convert.bson.BsonConvert;
+import org.redkale.util.Utility;
+import org.redkale.net.sncp.ServiceWrapper;
+import org.redkale.util.AnyValue;
+import org.redkale.watch.WatchFactory;
+import org.redkale.util.ResourceFactory;
+import java.io.*;
+import java.net.*;
+import java.nio.*;
+import java.nio.channels.*;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+import java.util.logging.*;
+import org.redkale.util.*;
+
+/**
+ *
+ * @author zhangjx
+ */
+public class SncpTest {
+
+ private static final String serviceName = "";
+
+ private static final String myhost = Utility.localInetAddress().getHostAddress();
+
+ private static final int port = 4040;
+
+ private static final int port2 = 4240;
+
+ public static void main(String[] args) throws Exception {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ final PrintStream ps = new PrintStream(out);
+ ps.println("handlers = java.util.logging.ConsoleHandler");
+ ps.println(".handlers = java.util.logging.ConsoleHandler");
+ ps.println(".level = FINEST");
+ ps.println("java.util.logging.ConsoleHandler.level = FINEST");
+ LogManager.getLogManager().readConfiguration(new ByteArrayInputStream(out.toByteArray()));
+ ResourceFactory.root().register("", BsonConvert.class, BsonFactory.root().getConvert());
+ if (System.getProperty("client") == null) {
+ runServer();
+ if (port2 > 0) runServer2();
+ }
+ if (System.getProperty("server") == null) {
+ runClient();
+ }
+ if (System.getProperty("server") != null) {
+ System.in.read();
+ }
+ }
+
+ public static AsynchronousChannelGroup newChannelGroup() throws IOException {
+ final AtomicInteger counter = new AtomicInteger();
+ ExecutorService transportExec = Executors.newFixedThreadPool(16, (Runnable r) -> {
+ Thread t = new Thread(r);
+ t.setDaemon(true);
+ t.setName("Transport-Thread-" + counter.incrementAndGet());
+ return t;
+ });
+ return AsynchronousChannelGroup.withCachedThreadPool(transportExec, 1);
+ }
+
+ public static ObjectPool newBufferPool() {
+ return new ObjectPool<>(new AtomicLong(), new AtomicLong(), 16,
+ (Object... params) -> ByteBuffer.allocateDirect(8192), null, (e) -> {
+ if (e == null || e.isReadOnly() || e.capacity() != 8192) return false;
+ e.clear();
+ return true;
+ });
+ }
+
+ private static void runClient() throws Exception {
+ InetSocketAddress addr = new InetSocketAddress(myhost, port);
+ Set set = new LinkedHashSet<>();
+ set.add(addr);
+ if (port2 > 0) set.add(new InetSocketAddress(myhost, port2));
+ //String name, WatchFactory, ObjectPool, AsynchronousChannelGroup, InetSocketAddress clientAddress, Collection
+ final Transport transport = new Transport("", WatchFactory.root(), newBufferPool(), newChannelGroup(), null, set);
+ final SncpTestService service = Sncp.createRemoteService(serviceName, null, SncpTestService.class, null, transport);
+ ResourceFactory.root().inject(service);
+
+// SncpTestBean bean = new SncpTestBean();
+// StringBuilder sb = new StringBuilder();
+// for (int i = 0; i < 2000; i++) {
+// sb.append("_").append(i).append("_0123456789");
+// }
+// bean.setContent(sb.toString());
+// bean.setContent("hello sncp");
+ SncpTestBean callbean = new SncpTestBean();
+ callbean.setId(1);
+ callbean.setContent("数据X");
+
+ service.insert(callbean);
+ System.out.println("bean.id应该会被修改: " + callbean);
+ System.out.println("---------------------------------------------------");
+ final int count = 10;
+ final CountDownLatch cld = new CountDownLatch(count);
+ final AtomicInteger ai = new AtomicInteger();
+ for (int i = 0; i < count; i++) {
+ final int k = i + 1;
+ new Thread() {
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(k);
+ SncpTestBean bean = new SncpTestBean();
+ bean.setId(k);
+ bean.setContent("数据: " + (k < 10 ? "0" : "") + k);
+ StringBuilder sb = new StringBuilder();
+ sb.append(k).append("------");
+ for (int i = 0; i < 1200; i++) {
+ sb.append("_").append(i).append("_").append(k).append("_0123456789");
+ }
+ bean.setContent(sb.toString());
+
+ service.queryResult(bean);
+ //service.updateBean(bean);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ long a = ai.incrementAndGet();
+ System.out.println("运行了 " + (a == 100 ? "--------------------------------------------------" : "") + a);
+ cld.countDown();
+ }
+ }
+ }.start();
+ }
+ cld.await();
+ System.out.println("---全部运行完毕---");
+ System.exit(0);
+ }
+
+ private static void runServer() throws Exception {
+ InetSocketAddress addr = new InetSocketAddress(myhost, port);
+ final CountDownLatch cdl = new CountDownLatch(1);
+ new Thread() {
+ {
+ setName("Thread-Server-01");
+ }
+
+ @Override
+ public void run() {
+ try {
+ SncpServer server = new SncpServer();
+ Set set = new LinkedHashSet<>();
+ if (port2 > 0) set.add(new InetSocketAddress(myhost, port2));
+ //String name, WatchFactory, ObjectPool, AsynchronousChannelGroup, InetSocketAddress clientAddress, Collection
+ final Transport transport = new Transport("", WatchFactory.root(), newBufferPool(), newChannelGroup(), null, set);
+ SncpTestService service = Sncp.createLocalService("", null, ResourceFactory.root(), SncpTestService.class, addr, transport, null);
+ ResourceFactory.root().inject(service);
+ server.addService(new ServiceWrapper(SncpTestService.class, service, "", "", new HashSet<>(), null));
+ System.out.println(service);
+ AnyValue.DefaultAnyValue conf = new AnyValue.DefaultAnyValue();
+ conf.addValue("host", "0.0.0.0");
+ conf.addValue("port", "" + port);
+ server.init(conf);
+ server.start();
+ cdl.countDown();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }.start();
+ cdl.await();
+ }
+
+ private static void runServer2() throws Exception {
+ InetSocketAddress addr = new InetSocketAddress(myhost, port2);
+ final CountDownLatch cdl = new CountDownLatch(1);
+ new Thread() {
+ {
+ setName("Thread-Server-02");
+ }
+
+ @Override
+ public void run() {
+ try {
+ SncpServer server = new SncpServer();
+ Set set = new LinkedHashSet<>();
+ set.add(new InetSocketAddress(myhost, port));
+ //String name, WatchFactory, ObjectPool, AsynchronousChannelGroup, InetSocketAddress clientAddress, Collection
+ final Transport transport = new Transport("", WatchFactory.root(), newBufferPool(), newChannelGroup(), null, set);
+ Service service = Sncp.createLocalService("", null, ResourceFactory.root(), SncpTestService.class, addr, transport, null);
+ server.addService(new ServiceWrapper(SncpTestService.class, service, "", "", new HashSet<>(), null));
+ AnyValue.DefaultAnyValue conf = new AnyValue.DefaultAnyValue();
+ conf.addValue("host", "0.0.0.0");
+ conf.addValue("port", "" + port2);
+ server.init(conf);
+ server.start();
+ cdl.countDown();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }.start();
+ cdl.await();
+ }
+}
diff --git a/test/org/redkale/test/sncp/SncpTestBean.java b/test/org/redkale/test/sncp/SncpTestBean.java
new file mode 100644
index 000000000..77684df5e
--- /dev/null
+++ b/test/org/redkale/test/sncp/SncpTestBean.java
@@ -0,0 +1,54 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.sncp;
+
+import org.redkale.convert.bson.BsonFactory;
+import org.redkale.util.Utility;
+import org.redkale.source.FilterBean;
+import javax.persistence.*;
+import org.redkale.convert.json.*;
+
+/**
+ *
+ * @author zhangjx
+ */
+public class SncpTestBean implements FilterBean {
+
+ @Id
+ private long id;
+
+ private String content;
+
+ public static void main(String[] args) throws Exception {
+ SncpTestBean bean = JsonConvert.root().convertFrom(SncpTestBean.class, "{\"content\":\"数据: 01\",\"id\":1}");
+ System.out.println(bean);
+ byte[] bs = BsonFactory.root().getConvert().convertTo(bean);
+ Utility.println("---------", bs);
+ System.out.println(BsonFactory.root().getConvert().convertFrom(SncpTestBean.class, bs).toString());
+ }
+
+ @Override
+ public String toString() {
+ return JsonConvert.root().convertTo(this);
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+}
diff --git a/test/org/redkale/test/sncp/SncpTestIService.java b/test/org/redkale/test/sncp/SncpTestIService.java
new file mode 100644
index 000000000..0d9c554e1
--- /dev/null
+++ b/test/org/redkale/test/sncp/SncpTestIService.java
@@ -0,0 +1,20 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.sncp;
+
+import org.redkale.service.*;
+import org.redkale.source.*;
+
+/**
+ *
+ * @author zhangjx
+ */
+public interface SncpTestIService extends Service {
+
+ public void insert(@DynCall(DataCallArrayAttribute.class) SncpTestBean... beans);
+
+ public String updateBean(@DynCall(SncpTestService.CallAttribute.class) SncpTestBean bean);
+}
diff --git a/test/org/redkale/test/sncp/SncpTestService.java b/test/org/redkale/test/sncp/SncpTestService.java
new file mode 100644
index 000000000..260118d92
--- /dev/null
+++ b/test/org/redkale/test/sncp/SncpTestService.java
@@ -0,0 +1,101 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.sncp;
+
+import java.lang.reflect.*;
+import java.net.*;
+import org.redkale.net.sncp.*;
+import org.redkale.service.*;
+import org.redkale.util.Attribute;
+import org.redkale.source.DataCallArrayAttribute;
+import org.redkale.util.*;
+
+/**
+ *
+ * @author zhangjx
+ */
+@ResourceType({SncpTestIService.class})
+public class SncpTestService implements SncpTestIService {
+
+ public static class CallAttribute implements Attribute {
+
+ @Override
+ public Class extends Long> type() {
+ return long.class;
+ }
+
+ @Override
+ public Class declaringClass() {
+ return SncpTestBean.class;
+ }
+
+ @Override
+ public String field() {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public Long get(SncpTestBean obj) {
+ System.out.println("返回ID: " + obj.getId());
+ return obj.getId();
+ }
+
+ @Override
+ public void set(SncpTestBean obj, Long value) {
+ System.out.println("设置ID: " + value);
+ obj.setId(value);
+ }
+
+ }
+
+ public void insert(@DynCall(DataCallArrayAttribute.class) SncpTestBean... beans) {
+ for (SncpTestBean bean : beans) {
+ bean.setId(System.currentTimeMillis());
+ }
+ }
+
+ public String queryResult(SncpTestBean bean) {
+ System.out.println(Thread.currentThread().getName() + " 运行了queryResult方法");
+ return "result: " + bean;
+ }
+
+ @MultiRun
+ public String updateBean(@DynCall(CallAttribute.class) SncpTestBean bean) {
+ bean.setId(System.currentTimeMillis());
+ System.out.println(Thread.currentThread().getName() + " 运行了updateBean方法");
+ return "result: " + bean;
+ }
+
+ public static void main(String[] args) throws Exception {
+ Service service = Sncp.createLocalService("", null, ResourceFactory.root(), SncpTestService.class, new InetSocketAddress("127.0.0.1", 7070), null, null);
+ for (Method method : service.getClass().getDeclaredMethods()) {
+ System.out.println(method);
+ }
+ System.out.println("-----------------------------------");
+ for (Method method : SncpClient.parseMethod(service.getClass())) {
+ System.out.println(method);
+ }
+ System.out.println("-----------------------------------");
+ service = Sncp.createRemoteService("", null, SncpTestService.class, new InetSocketAddress("127.0.0.1", 7070), null);
+ for (Method method : service.getClass().getDeclaredMethods()) {
+ System.out.println(method);
+ }
+ System.out.println("-----------------------------------");
+ for (Method method : SncpClient.parseMethod(service.getClass())) {
+ System.out.println(method);
+ }
+ System.out.println("-----------------------------------");
+ service = Sncp.createRemoteService("", null, SncpTestIService.class, new InetSocketAddress("127.0.0.1", 7070), null);
+ for (Method method : service.getClass().getDeclaredMethods()) {
+ System.out.println(method);
+ }
+ System.out.println("-----------------------------------");
+ for (Method method : SncpClient.parseMethod(service.getClass())) {
+ System.out.println(method);
+ }
+ System.out.println("-----------------------------------");
+ }
+}
diff --git a/test/org/redkale/test/source/CacheTestBean.java b/test/org/redkale/test/source/CacheTestBean.java
new file mode 100644
index 000000000..fa636a7de
--- /dev/null
+++ b/test/org/redkale/test/source/CacheTestBean.java
@@ -0,0 +1,81 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.source;
+
+import org.redkale.source.EntityInfo;
+import org.redkale.source.EntityCache;
+import org.redkale.util.Attribute;
+import java.util.*;
+import javax.persistence.*;
+import org.redkale.source.*;
+
+/**
+ *
+ * @author zhangjx
+ */
+public class CacheTestBean {
+
+ @Id
+ private long pkgid;
+
+ private String name;
+
+ private long price;
+
+ public static void main(String[] args) throws Exception {
+ final List list = new ArrayList<>();
+ list.add(new CacheTestBean(1, "a", 12));
+ list.add(new CacheTestBean(1, "a", 18));
+ list.add(new CacheTestBean(2, "b", 20));
+ list.add(new CacheTestBean(2, "bb", 60));
+ Attribute idattr = Attribute.create(CacheTestBean.class, "pkgid");
+ Attribute nameattr = Attribute.create(CacheTestBean.class, "name");
+ Attribute priceattr = Attribute.create(CacheTestBean.class, "price");
+ EntityCache cache = new EntityCache(EntityInfo.load(CacheTestBean.class, 0, true,new Properties(), null));
+ cache.fullLoad(list);
+
+ System.out.println(cache.queryColumnMap("pkgid", FilterFunc.COUNT, "name", null));
+ System.out.println(cache.queryColumnMap("pkgid", FilterFunc.DISTINCTCOUNT, "name", null));
+ System.out.println(cache.queryColumnMap("pkgid", FilterFunc.AVG, "price", null));
+ System.out.println(cache.queryColumnMap("pkgid", FilterFunc.SUM, "price", null));
+ System.out.println(cache.queryColumnMap("pkgid", FilterFunc.MAX, "price", null));
+ System.out.println(cache.queryColumnMap("pkgid", FilterFunc.MIN, "price", null));
+ }
+
+ public CacheTestBean() {
+ }
+
+ public CacheTestBean(long pkgid, String name, long price) {
+ this.pkgid = pkgid;
+ this.name = name;
+ this.price = price;
+ }
+
+ public long getPkgid() {
+ return pkgid;
+ }
+
+ public void setPkgid(long pkgid) {
+ this.pkgid = pkgid;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public long getPrice() {
+ return price;
+ }
+
+ public void setPrice(long price) {
+ this.price = price;
+ }
+
+}
diff --git a/test/org/redkale/test/source/JDBCTest.java b/test/org/redkale/test/source/JDBCTest.java
new file mode 100644
index 000000000..a8d782334
--- /dev/null
+++ b/test/org/redkale/test/source/JDBCTest.java
@@ -0,0 +1,42 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.source;
+
+import org.redkale.source.DataDefaultSource;
+import org.redkale.source.DataSource;
+
+/**
+ *
+ * @author zhangjx
+ */
+public class JDBCTest {
+
+ public static void main(String[] args) throws Exception {
+ DataSource source = new DataDefaultSource(); //耗时:37415
+ int count = 1000;
+ LoginTestRecord last = null;
+ long s = System.currentTimeMillis();
+ int c = 0;
+ try {
+ for (int i = 0; i < count; i++) {
+ LoginTestRecord record = new LoginTestRecord();
+ record.setSessionid(Long.toHexString(System.nanoTime()));
+ record.setLoginagent("win7");
+ record.setLogintime(System.currentTimeMillis());
+ record.setLoginip("127.0.0.1");
+ record.setUserid(i);
+ source.insert(record);
+ last = record;
+ c = i;
+ }
+ } catch (Exception e) {
+ System.out.println("异常了: " + c);
+ e.printStackTrace();
+ }
+ long e = System.currentTimeMillis() - s;
+ System.out.println("耗时:" + e);
+ }
+}
diff --git a/test/org/redkale/test/source/LoginTestBean.java b/test/org/redkale/test/source/LoginTestBean.java
new file mode 100644
index 000000000..1310b5ec9
--- /dev/null
+++ b/test/org/redkale/test/source/LoginTestBean.java
@@ -0,0 +1,26 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.source;
+
+import org.redkale.source.FilterBean;
+
+/**
+ *
+ * @author zhangjx
+ */
+public class LoginTestBean implements FilterBean {
+
+ private String sessionid;
+
+ public String getSessionid() {
+ return sessionid;
+ }
+
+ public void setSessionid(String sessionid) {
+ this.sessionid = sessionid;
+ }
+
+}
diff --git a/test/org/redkale/test/source/LoginTestRecord.java b/test/org/redkale/test/source/LoginTestRecord.java
new file mode 100644
index 000000000..6e99d6967
--- /dev/null
+++ b/test/org/redkale/test/source/LoginTestRecord.java
@@ -0,0 +1,95 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.source;
+
+import javax.persistence.*;
+import org.redkale.convert.json.*;
+
+/**
+ * CREATE TABLE `LoginTestRecord` (
+ * `sessionid` VARCHAR(64) NOT NULL COMMENT '登陆会话ID',
+ * `userid` INT(11) NOT NULL COMMENT '登陆用户ID',
+ * `loginagent` VARCHAR(128) NOT NULL COMMENT '登陆端信息',
+ * `loginip` VARCHAR(255) NOT NULL COMMENT '登陆IP',
+ * `logintime` BIGINT(20) NOT NULL COMMENT '登陆时间',
+ * `logouttime` BIGINT(20) NOT NULL COMMENT '注销时间',
+ * PRIMARY KEY (`sessionid`)
+ * ) ENGINE=INNODB DEFAULT CHARSET=utf8;
+ *
+ * @author zhangjx
+ */
+@Entity
+public class LoginTestRecord {
+
+ @Id
+ @GeneratedValue
+ //@SequenceGenerator(name = "SEQ", initialValue = 100001, allocationSize = 1000)
+ private String sessionid;
+
+ private int userid;
+
+ private String loginagent;
+
+ private String loginip;
+
+ private long logintime;
+
+ private long logouttime;
+
+ @Override
+ public String toString() {
+ return JsonConvert.root().convertTo(this);
+ }
+
+ public String getSessionid() {
+ return sessionid;
+ }
+
+ public void setSessionid(String sessionid) {
+ this.sessionid = sessionid;
+ }
+
+ public int getUserid() {
+ return userid;
+ }
+
+ public void setUserid(int userid) {
+ this.userid = userid;
+ }
+
+ public String getLoginagent() {
+ return loginagent;
+ }
+
+ public void setLoginagent(String loginagent) {
+ this.loginagent = loginagent;
+ }
+
+ public String getLoginip() {
+ return loginip;
+ }
+
+ public void setLoginip(String loginip) {
+ this.loginip = loginip;
+ }
+
+ public long getLogintime() {
+ return logintime;
+ }
+
+ public void setLogintime(long logintime) {
+ this.logintime = logintime;
+ }
+
+ public long getLogouttime() {
+ return logouttime;
+ }
+
+ public void setLogouttime(long logouttime) {
+ this.logouttime = logouttime;
+ }
+
+}
diff --git a/test/org/redkale/test/source/TestSourceCache.java b/test/org/redkale/test/source/TestSourceCache.java
new file mode 100644
index 000000000..cf7f6e2dd
--- /dev/null
+++ b/test/org/redkale/test/source/TestSourceCache.java
@@ -0,0 +1,134 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.source;
+
+import java.util.*;
+import org.redkale.source.VirtualEntity;
+import org.redkale.source.FilterNodeBean;
+import org.redkale.source.FilterExpress;
+import org.redkale.source.FilterColumn;
+import org.redkale.util.Sheet;
+import org.redkale.source.FilterBean;
+import org.redkale.source.Flipper;
+import org.redkale.source.EntityInfo;
+import org.redkale.source.FilterNode;
+import java.util.concurrent.*;
+import javax.persistence.*;
+import org.redkale.convert.json.*;
+
+/**
+ *
+ * @author zhangjx
+ */
+public class TestSourceCache {
+
+ public static class TestEntityBean implements FilterBean {
+
+ @FilterColumn(express = FilterExpress.GREATERTHAN)
+ public int userid;
+
+ @FilterColumn(express = FilterExpress.LIKE)
+ public String username;
+
+ public TestEntityBean(int userid, String username) {
+ this.userid = userid;
+ this.username = username;
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ final EntityInfo info = EntityInfo.load(TestEntity.class, 0, false,new Properties(), null);
+ TestEntity[] entitys = new TestEntity[10_0000];
+ for (int i = 0; i < entitys.length; i++) {
+ entitys[i] = new TestEntity(i + 1, "用户_" + (i + 1));
+ }
+ long s = System.currentTimeMillis();
+ for (TestEntity en : entitys) {
+ info.getCache().insert(en);
+ }
+ long e = System.currentTimeMillis() - s;
+ System.out.println("插入十万条记录耗时: " + e / 1000.0 + " 秒");
+
+ s = System.currentTimeMillis();
+ TestEntity one = info.getCache().find(9999);
+ e = System.currentTimeMillis() - s;
+ System.out.println("十万条数据中查询一条记录耗时: " + e / 1000.0 + " 秒 " + one);
+
+ final Flipper flipper = new Flipper(2);
+ flipper.setSort("userid DESC, createtime DESC");
+ final FilterNode node = FilterNode.create("userid", FilterExpress.GREATERTHAN, 1000).and("username", FilterExpress.LIKE, "用户");
+ System.out.println("node = " + node);
+ Sheet sheet = info.getCache().querySheet(null, flipper, node);
+ System.out.println(sheet);
+ System.out.println(info.getCache().querySheet(null, flipper, FilterNodeBean.createFilterNode(new TestEntityBean(1000, "用户"))));
+ final CountDownLatch cdl = new CountDownLatch(100);
+ s = System.currentTimeMillis();
+ for (int i = 0; i < 100; i++) {
+ new Thread() {
+ @Override
+ public void run() {
+ for (int k = 0; k < 10; k++) {
+ info.getCache().querySheet(true, null, flipper, node);
+ }
+ cdl.countDown();
+ }
+ }.start();
+ }
+ cdl.await();
+ e = System.currentTimeMillis() - s;
+ System.out.println("十万条数据中查询一页记录耗时: " + e / 1000.0 + " 秒 " + sheet); // CopyOnWriteArrayList 0.798 ConcurrentLinkedQueue 1.063
+ }
+
+ @VirtualEntity
+ @Cacheable
+ public static class TestEntity {
+
+ @Id
+ private int userid;
+
+ private String username;
+
+ private long createtime = System.currentTimeMillis();
+
+ public TestEntity() {
+
+ }
+
+ public TestEntity(int userid, String username) {
+ this.userid = userid;
+ this.username = username;
+ }
+
+ public int getUserid() {
+ return userid;
+ }
+
+ public void setUserid(int userid) {
+ this.userid = userid;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public long getCreatetime() {
+ return createtime;
+ }
+
+ public void setCreatetime(long createtime) {
+ this.createtime = createtime;
+ }
+
+ @Override
+ public String toString() {
+ return JsonConvert.root().convertTo(this);
+ }
+ }
+}
diff --git a/test/org/redkale/test/util/CreatorRecord.java b/test/org/redkale/test/util/CreatorRecord.java
new file mode 100644
index 000000000..a9d4d41f4
--- /dev/null
+++ b/test/org/redkale/test/util/CreatorRecord.java
@@ -0,0 +1,97 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.util;
+
+import java.beans.*;
+import org.redkale.convert.json.*;
+import org.redkale.util.*;
+
+/**
+ *
+ * @author zhangjx
+ */
+public class CreatorRecord {
+
+ private int id = -1;
+
+ private String name;
+
+ private long lval;
+
+ private boolean tval;
+
+ private byte bval;
+
+ private short sval;
+
+ private char cval;
+
+ private float fval;
+
+ private double dval;
+
+ @ConstructorProperties({"id", "name", "lval", "tval", "bval", "sval", "cval", "fval", "dval"})
+ CreatorRecord(int id, String name, long lval, boolean tval, byte bval, short sval, char cval, float fval, double dval) {
+ this.id = id;
+ this.name = name;
+ this.lval = lval;
+ this.tval = tval;
+ this.bval = bval;
+ this.sval = sval;
+ this.cval = cval;
+ this.fval = fval;
+ this.dval = dval;
+ }
+
+ public static void main(String[] args) throws Exception {
+ CreatorRecord record = Creator.create(CreatorRecord.class).create(new Object[]{null, "ss", null, true, null, (short) 45, null, 4.3f, null});
+ String json = record.toString();
+ System.out.println(json);
+ System.out.println(JsonConvert.root().convertFrom(CreatorRecord.class, json).toString());
+ }
+
+ @Override
+ public String toString() {
+ return JsonConvert.root().convertTo(this);
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public long getLval() {
+ return lval;
+ }
+
+ public boolean isTval() {
+ return tval;
+ }
+
+ public byte getBval() {
+ return bval;
+ }
+
+ public short getSval() {
+ return sval;
+ }
+
+ public char getCval() {
+ return cval;
+ }
+
+ public float getFval() {
+ return fval;
+ }
+
+ public double getDval() {
+ return dval;
+ }
+
+}
diff --git a/test/org/redkale/test/util/ResourceTest.java b/test/org/redkale/test/util/ResourceTest.java
new file mode 100644
index 000000000..5460d5000
--- /dev/null
+++ b/test/org/redkale/test/util/ResourceTest.java
@@ -0,0 +1,153 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template bigint, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.util;
+
+import java.math.*;
+import javax.annotation.*;
+import org.redkale.util.*;
+
+/**
+ *
+ * @author zhangjx
+ */
+public class ResourceTest {
+
+public static void main(String[] args) throws Exception {
+ ResourceFactory factory = ResourceFactory.root();
+ factory.register("property.id", "2345"); //注入String类型的property.id
+ AService aservice = new AService();
+ BService bservice = new BService("eeeee");
+
+ factory.register(aservice); //放进Resource池内,默认的资源名name为""
+ factory.register(bservice); //放进Resource池内,默认的资源名name为""
+
+ factory.inject(aservice); //给aservice注入id、bservice,bigint没有资源,所以为null
+ factory.inject(bservice); //给bservice注入id、aservice
+ System.out.println(aservice); //输出结果为:{id:"2345", intid: 2345, bigint:null, bservice:{name:eeeee}}
+ System.out.println(bservice); //输出结果为:{name:"eeeee", id: 2345, aserivce:{id:"2345", intid: 2345, bigint:null, bservice:{name:eeeee}}}
+
+ factory.register("seqid", 200); //放进Resource池内, 同时ResourceFactory会自动更新aservice的seqid值
+ System.out.println(factory.find("seqid", int.class)); //输出结果为:200
+ factory.register("bigint", new BigInteger("666666666666666")); //放进Resource池内, 同时ResourceFactory会自动更新aservice对象的bigint值
+ System.out.println(aservice); //输出结果为:{id:"2345", intid: 2345, bigint:666666666666666, bservice:{name:eeeee}} 可以看出seqid与bigint值都已自动更新
+
+ factory.register("property.id", "6789"); //更新Resource池内的id资源值, 同时ResourceFactory会自动更新aservice、bservice的id值
+ System.out.println(aservice); //输出结果为:{id:"6789", intid: 6789, bigint:666666666666666, bservice:{name:eeeee}}
+ System.out.println(bservice); //输出结果为:{name:"eeeee", id: 6789, aserivce:{id:"6789", intid: 6789, bigint:666666666666666, bservice:{name:eeeee}}}
+
+ bservice = new BService("ffff");
+ factory.register(bservice); //更新Resource池内name=""的BService资源, 同时ResourceFactory会自动更新aservice的bservice对象
+ factory.inject(bservice);
+ System.out.println(aservice); //输出结果为:{id:"6789", intid: 6789, bigint:666666666666666, bservice:{name:ffff}}
+
+}
+
+}
+
+class BService {
+
+ @Resource(name = "property.id")
+ private String id;
+
+ @Resource
+ private AService aservice;
+
+ private String name = "";
+
+ @java.beans.ConstructorProperties({"name"})
+ public BService(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public AService getAservice() {
+ return aservice;
+ }
+
+ public void setAservice(AService aservice) {
+ this.aservice = aservice;
+ }
+
+ @Override
+ public String toString() {
+ return "{name:\"" + name + "\", id: " + id + ", aserivce:" + aservice + "}";
+ }
+}
+
+class AService {
+
+ @Resource(name = "property.id")
+ private String id;
+
+ @Resource(name = "property.id") //property.开头的资源名允许String自动转换成primitive数值类型
+ private int intid;
+
+ @Resource(name = "bigint")
+ private BigInteger bigint;
+
+ @Resource(name = "seqid")
+ private int seqid;
+
+ @Resource
+ private BService bservice;
+
+ @Override
+ public String toString() {
+ return "{id:\"" + id + "\", intid: " + intid + ", bigint:" + bigint + ", bservice:" + (bservice == null ? null : ("{name:" + bservice.getName() + "}")) + "}";
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public int getIntid() {
+ return intid;
+ }
+
+ public void setIntid(int intid) {
+ this.intid = intid;
+ }
+
+ public int getSeqid() {
+ return seqid;
+ }
+
+ public void setSeqid(int seqid) {
+ this.seqid = seqid;
+ }
+
+ public BigInteger getBigint() {
+ return bigint;
+ }
+
+ public void setBigint(BigInteger bigint) {
+ this.bigint = bigint;
+ }
+
+ public void setBservice(BService bservice) {
+ this.bservice = bservice;
+ }
+
+}
diff --git a/test/org/redkale/test/util/TestABean.java b/test/org/redkale/test/util/TestABean.java
new file mode 100644
index 000000000..9e594f310
--- /dev/null
+++ b/test/org/redkale/test/util/TestABean.java
@@ -0,0 +1,14 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.util;
+
+/**
+ *
+ * @author zhangjx
+ */
+public class TestABean {
+ public long time;
+}
diff --git a/test/org/redkale/test/util/TestBean.java b/test/org/redkale/test/util/TestBean.java
new file mode 100644
index 000000000..9f9f77c93
--- /dev/null
+++ b/test/org/redkale/test/util/TestBean.java
@@ -0,0 +1,46 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.util;
+
+import java.util.Map;
+
+/**
+ *
+ * @author zhangjx
+ */
+public class TestBean extends TestABean {
+
+ private String name;
+
+ private int id;
+
+ private Map map;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public Map getMap() {
+ return map;
+ }
+
+ public void setMap(Map map) {
+ this.map = map;
+ }
+
+}
diff --git a/test/org/redkale/test/util/TestXBean.java b/test/org/redkale/test/util/TestXBean.java
new file mode 100644
index 000000000..d7fe82282
--- /dev/null
+++ b/test/org/redkale/test/util/TestXBean.java
@@ -0,0 +1,15 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.redkale.test.util;
+
+/**
+ *
+ * @author zhangjx
+ */
+public class TestXBean extends TestBean{
+
+}
diff --git a/test/org/redkale/test/util/UntilTestMain.java b/test/org/redkale/test/util/UntilTestMain.java
new file mode 100644
index 000000000..33f147e9b
--- /dev/null
+++ b/test/org/redkale/test/util/UntilTestMain.java
@@ -0,0 +1,103 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.util;
+
+import org.redkale.util.Reproduce;
+import org.redkale.util.Attribute;
+
+/**
+ *
+ * @author zhangjx
+ */
+public class UntilTestMain {
+
+ public static void main(String[] args) throws Throwable {
+ reproduce(args);
+ attribute(args);
+ }
+
+ public static void reproduce(String[] args) throws Throwable {
+ final TestBean bean = new TestBean();
+ bean.setId(123456);
+ bean.setName("zhangjx");
+ bean.time = 2000;
+ final TestXBean beanx = new TestXBean();
+ Reproduce action1 = Reproduce.create(TestXBean.class, TestBean.class);
+ Reproduce action2 = new Reproduce() {
+
+ @Override
+ public TestXBean copy(TestXBean dest, TestBean src) {
+ dest.time = src.time;
+ dest.setId(src.getId());
+ dest.setName(src.getName());
+ dest.setMap(src.getMap());
+ return dest;
+ }
+ };
+ final int count = 1_000_000;
+ long s = System.nanoTime();
+ for (int i = 0; i < count; i++) {
+ action2.copy(beanx, bean);
+ }
+ long e = System.nanoTime() - s;
+ System.out.println("静态Reproduce耗时: " + e);
+ s = System.nanoTime();
+ for (int i = 0; i < count; i++) {
+ action1.copy(beanx, bean);
+ }
+ e = System.nanoTime() - s;
+ System.out.println("动态Reproduce耗时: " + e);
+ System.out.println();
+ }
+
+ public static void attribute(String[] args) throws Throwable {
+ final TestBean bean = new TestBean();
+ bean.setId(123456);
+ bean.setName("zhangjx");
+ Attribute action1 = Attribute.create(TestBean.class.getDeclaredField("name"));
+ Attribute action2 = new Attribute() {
+
+ @Override
+ public String field() {
+ return "name";
+ }
+
+ @Override
+ public String get(TestBean obj) {
+ return obj.getName();
+ }
+
+ @Override
+ public void set(TestBean obj, String value) {
+ obj.setName(value);
+ }
+
+ @Override
+ public Class type() {
+ return String.class;
+ }
+
+ @Override
+ public Class declaringClass() {
+ return TestBean.class;
+ }
+ };
+ final int count = 1_000_000;
+ long s = System.nanoTime();
+ for (int i = 0; i < count; i++) {
+ action2.set(bean, "zhangjx2");
+ }
+ long e = System.nanoTime() - s;
+ System.out.println("静态Attribute耗时: " + e);
+ s = System.nanoTime();
+ for (int i = 0; i < count; i++) {
+ action1.set(bean, "zhangjx2");
+ }
+ e = System.nanoTime() - s;
+ System.out.println("动态Attribute耗时: " + e);
+ System.out.println();
+ }
+}
diff --git a/test/org/redkale/test/websocket/ChatWebSocketServlet.java b/test/org/redkale/test/websocket/ChatWebSocketServlet.java
new file mode 100644
index 000000000..ff5410646
--- /dev/null
+++ b/test/org/redkale/test/websocket/ChatWebSocketServlet.java
@@ -0,0 +1,77 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.websocket;
+
+import org.redkale.net.http.WebServlet;
+import org.redkale.net.http.WebSocketServlet;
+import org.redkale.net.http.WebSocket;
+import java.io.*;
+import static java.lang.Thread.sleep;
+import java.text.*;
+import java.util.concurrent.atomic.*;
+import static java.lang.Thread.sleep;
+import static java.lang.Thread.sleep;
+import static java.lang.Thread.sleep;
+
+/**
+ *
+ * @author zhangjx
+ */
+@WebServlet("/ws/chat")
+public class ChatWebSocketServlet extends WebSocketServlet {
+
+ private final AtomicLong counter = new AtomicLong();
+
+ private final AtomicLong icounter = new AtomicLong();
+
+ private final boolean debug;
+
+ public ChatWebSocketServlet() {
+ debug = "true".equalsIgnoreCase(System.getProperty("debug", "false"));
+ Thread t = new Thread() {
+
+ private final DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+ {
+ setName("Debug-ChatWebSocket-ShowCount-Thread");
+ }
+
+ @Override
+ public void run() {
+ while (true) {
+ try {
+ sleep(60 * 1000);
+ } catch (Exception e) {
+ return;
+ }
+ System.out.println(format.format(new java.util.Date()) + ": 消息总数: " + counter.get() + ",间隔消息数: " + icounter.getAndSet(0));
+ }
+ }
+ };
+ t.start();
+ }
+
+ @Override
+ protected WebSocket createWebSocket() {
+
+ return new WebSocket() {
+
+ @Override
+ public void onMessage(String text) {
+ icounter.incrementAndGet();
+ counter.incrementAndGet();
+ if (debug) System.out.println("收到消息: " + text);
+ super.getWebSocketGroup().getWebSockets().forEach(x -> x.send(text));
+ }
+
+ @Override
+ protected Serializable createGroupid() {
+ return "";
+ }
+ };
+ }
+
+}
diff --git a/test/org/redkale/test/websocket/Flash843.java b/test/org/redkale/test/websocket/Flash843.java
new file mode 100644
index 000000000..bd29f8ddf
--- /dev/null
+++ b/test/org/redkale/test/websocket/Flash843.java
@@ -0,0 +1,29 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.websocket;
+
+import java.io.ByteArrayOutputStream;
+import java.net.Socket;
+
+/**
+ *
+ * @author zhangjx
+ */
+public class Flash843 {
+
+ public static void main(String[] args) throws Exception {
+ Socket socket = new Socket("113.105.88.229", 843);
+ socket.getOutputStream().write("".getBytes());
+ socket.getOutputStream().flush();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] bytes = new byte[1024];
+ int pos;
+ while ((pos = socket.getInputStream().read(bytes)) != -1) {
+ out.write(bytes, 0, pos);
+ }
+ System.out.println(out.toString());
+ }
+}
diff --git a/test/org/redkale/test/websocket/VideoWebSocketServlet.java b/test/org/redkale/test/websocket/VideoWebSocketServlet.java
new file mode 100644
index 000000000..79bec9478
--- /dev/null
+++ b/test/org/redkale/test/websocket/VideoWebSocketServlet.java
@@ -0,0 +1,134 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.test.websocket;
+
+import org.redkale.net.http.WebServlet;
+import org.redkale.net.http.WebSocketServlet;
+import org.redkale.net.http.HttpRequest;
+import org.redkale.net.http.WebSocket;
+import org.redkale.net.http.HttpServer;
+import org.redkale.util.TypeToken;
+import org.redkale.util.AnyValue;
+import java.io.*;
+import java.util.*;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ *
+ * @author zhangjx
+ */
+@WebServlet({"/ws/listen"})
+public class VideoWebSocketServlet extends WebSocketServlet {
+
+ private final Map sessions = new java.util.concurrent.ConcurrentHashMap<>();
+
+ private final Map users = new HashMap<>();
+
+ private static final class Entry {
+
+ public WebSocket socket;
+
+ public String username;
+
+ public Serializable userid;
+
+ }
+
+ public VideoWebSocketServlet() {
+ super();
+ users.put("zhangjx", "xxxx");
+ }
+
+ @Override
+ protected WebSocket createWebSocket() {
+ WebSocket socket = new WebSocket() {
+
+ private final TypeToken