@Override public void sendText(final String body) { httpSendWebSocketCalled = true; periodicFlushCallback.accept(null); Sys.sleep(100); } };
public void serviceCall(final Callback<String> callback, final int seconds, String message) { Thread thread = new Thread(() -> { Sys.sleep(seconds * 1000); callback.accept(name + "::" + message); }); thread.start(); } }
@Override public void run() { while (true) { Sys.sleep(50); periodicFlushCallback.accept(null); sendQueue.flushSends(); if (thread.isInterrupted()) { break; } } } });
@RequestMapping(value = "/timeout") public boolean timeout() { while (true) { Sys.sleep(1000); } }
@RequestMapping("/timeOut") public String timeOut() { puts("TIMEOUT"); Sys.sleep(30000); return "ok"; }
@Test public void warning() throws Exception { Consul client = Consul.consul(); String serviceName = UUID.randomUUID().toString(); String serviceId = UUID.randomUUID().toString(); String note = UUID.randomUUID().toString(); client.agent().registerService("localhost", 80, 20L, serviceName, serviceId); client.agent().warn(serviceId, note); Sys.sleep(100); verifyState("warning", client, serviceId, serviceName); }
@Test public void test() { HTTP.Response response = HTTP.jsonRestCallViaPOST(buildURL("addall"), "[{\"i\": 1, \"s\": \"string\"}, " + "{\"i\": 2, \"s\": \"string2\"}]"); assertEquals(202, response.status()); while (ref.get() == null) { Sys.sleep(10); } assertNotNull(ref.get()); }
@After public void tearDown() throws Exception { client.flush(); Sys.sleep(1000); client.stop(); }
@Test public void testCreateProxy() throws Exception { client.start(); Sys.sleep(100); final ServiceMock mockService = client.createProxy(ServiceMock.class, "mockService"); mockService.add(1, 2); ((ClientProxy) mockService).clientProxyFlush(); Sys.sleep(100); ok = httpSendWebSocketCalled || die(); }
@After public void tearDown() throws Exception { serviceEndpointServer.stop(); httpClient.stop(); Sys.sleep(1000); }
@Test public void testCallBack() throws Exception { client.start(); Sys.sleep(100); final ServiceMock mockService = client.createProxy(ServiceMock.class, "mockService"); mockService.sum(integer -> puts("SUM", integer)); ((ClientProxy) mockService).clientProxyFlush(); Sys.sleep(100); ok = httpSendWebSocketCalled || die(); }
@Test public void fetchNode() throws UnknownHostException, NotRegisteredException { Consul client = Consul.consul(); String serviceName = UUID.randomUUID().toString(); String serviceId = UUID.randomUUID().toString(); client.agent().registerService(80, 20L, serviceName, serviceId); client.agent().pass(serviceId); Sys.sleep(1000); boolean found = false; ConsulResponse<List<ServiceHealth>> response = client.health().getAllNodes(serviceName); assertHealth(serviceId, found, response); }
@Test public void testAsyncCallHttp() throws Exception { final HttpRequest request = new HttpRequestBuilder().setUri("/services/mock/callWithReturn") .setTextReceiver(new MockReceiver()).setBody("").build(); httpServer.sendRequest(request); Sys.sleep(10); serviceServerImpl.flush(); Sys.sleep(10); waitForTrigger(20, o -> responseCounter == 1 && callMeCounter == 1); ok |= responseCounter == 1 || die(); ok |= callMeCounter == 1 || die(); ok |= lastResponse.equals("\"bacon\"") || die(); }
@Test public void testSimpleHTTPRequest() throws Exception { final HttpRequest request = new HttpRequestBuilder().setUri("/services/mock/callme").setTextReceiver(new MockReceiver()).setBody("").build(); httpServer.sendRequest(request); Sys.sleep(10); serviceServerImpl.flush(); Sys.sleep(10); waitForTrigger(20, o -> responseCounter == 1 && callMeCounter == 1); ok |= responseCounter == 1 || die(); ok |= callMeCounter == 1 || die(); }
@Test public void testSendConsume2() throws Exception { personSendQueue.sendAndFlush(new Person("Geoff")); personSendQueue.sendAndFlush(new Person("Rick")); final Person geoff = personReceiveQueue.pollWait(); Sys.sleep(100); final Person rick = personReceiveQueue.poll(); assertEquals("Geoff", geoff.name); assertEquals("Rick", rick.name); }
public static void main(String... args) { final HttpClient httpClient = httpClientBuilder().setAutoFlush(true).setPort(9999).build(); httpClient.startClient(); final WebSocket webSocket = httpClient.createWebSocket("/hello"); webSocket.setTextMessageConsumer(message -> puts("\n\n\n", message, "\n\n") ); webSocket.openAndWait(); webSocket.sendText("Hello"); Sys.sleep(100000); } }
@Test public void testWithService() { final ServiceQueue serviceQueue = serviceBuilder().setServiceObject(new MockService()).buildAndStart(); serviceBundle.addServiceQueue("mockService", serviceQueue); proxy = serviceBundle.createLocalProxy(MockServiceInterface.class, "mockService"); serviceBundle.startReturnHandlerProcessor(); proxy.method1(); proxy.clientProxyFlush(); Sys.sleep(1000); ok = callCount == 1 || die(); }
public void setupWithDebug() { lowLevelKVStore = LowLevelLocalKeyValueStoreServiceBuilder.localKeyValueStoreBuilder() .setTimer(timer) .buildAsServiceAndStartAll() .createProxy(LowLevelKeyValueStoreService.class); kvStore = LocalKeyValueStoreServiceBuilder.localKeyValueStoreServiceBuilder(Todo.class) .setTimer(timer).setDebug(true).setDebugInterval(Duration.ONE_HOUR) .setWriteBehindAndReadFallbackAsLowLevel(lowLevelKVStore) .buildAsServiceAndStartAll().createProxy(KeyValueStoreService.class); timer = new TestTimer(); Sys.sleep(100); }