@Override public Iterable<String> valueMulti() { /* We could support this. */ //noinspection unchecked return die(Iterable.class, "NOT SUPPORTED"); }
@SuppressWarnings("NullableProblems") @Override public Collection<String> values() { //noinspection unchecked return die(Collection.class, "Not supported"); }
private static String readErrorResponseBody(HttpURLConnection http, int status, String charset) { InputStream errorStream = http.getErrorStream(); if (errorStream != null) { String error = charset == null ? IO.read(errorStream) : IO.read(errorStream, charset); return Exceptions.die(String.class, "STATUS CODE =" + status + "\n\n" + error); } else { return Exceptions.die(String.class, "STATUS CODE =" + status); } }
private Message<Object> parseMessageFromChars(final String returnAddress, char[] chars) { final char messageType = chars[PROTOCOL_MESSAGE_TYPE_POSITION]; if (messageType == PROTOCOL_MESSAGE_TYPE_METHOD) { return handleFastBodySubmissionVersion1Chars(returnAddress, chars); } else if (messageType == PROTOCOL_MESSAGE_TYPE_RESPONSE) { return parseResponseFromChars(chars, returnAddress); } else { die("Unsupported method call", new String(chars)); return null; } }
@After public void tearDown() { callCount = 0; if (!ok) die(); }
@Test public void testWriteString() throws Exception { Buffer buffer = Buffer.buffer(); BufferUtils.writeString(buffer, "hi mom"); final short size = buffer.getShort(0); ok = size == 6 || die(); final String utf_8 = buffer.getString(2, size + 2, StandardCharsets.UTF_8.displayName()); puts(utf_8); ok = utf_8.equals("hi mom") || die(); }
@Test public void testStop() throws Exception { client.stop(); ok = httpStopCalled || die(); }
@Test public void testReadString() throws Exception { Buffer buffer = Buffer.buffer(); BufferUtils.writeString(buffer, "hi mom"); int[] location = new int[]{0}; String backOut = BufferUtils.readString(buffer, location); ok = backOut.equals("hi mom") || die(); }
@Test public void testTimeOut() throws Exception { timeOutCounter.set(0); Sys.sleep(10); final HttpRequest request = new HttpRequestBuilder().setUri("/services/mock/timeOut").setTextReceiver(new MockReceiver()).setBody("").build(); httpServer.sendRequest(request); waitForTrigger(20, o -> timeOutCounter.get() >= 1); ok |= responseCounter == 0 || die(); ok |= callMeCounter == 0 || die(); ok |= timeOutCounter.get() >= 1 || die(); //TODO fix }
@Test public void testRecord() throws Exception { statServiceClient.recordCount("mystat", 1); serviceBundle.flush(); triggerLatchWhen(o -> replicator.count.get() == 1); waitForLatch(20); ok = replicator.count.get() == 1 || die(); }
@Test public void testLastSecond() throws Exception { statServiceClient.recordCount("mystat", 1); serviceBundle.flush(); triggerLatchWhen(o -> replicator.count.get() == 1); waitForLatch(20); ok = replicator.count.get() == 1 || die(); }
@Test public void testWriteMap() throws Exception { Buffer buffer = Buffer.buffer(); MultiMap<String, String> map = new MultiMapImpl<>(); map.put("key", "value"); BufferUtils.writeMap(buffer, map); int[] location = new int[]{0}; MultiMap<String, String> map2 = BufferUtils.readMap(buffer, location); final String value = map2.get("key"); ok = value.equals("value") || die(); }
@Test public void test() { proxy.method1(); proxy.clientProxyFlush(); Sys.sleep(1000); ok = callCount == 1 || die(); }
@Test public void testRecordAll() throws Exception { String[] names = Arry.array("stat1", "stat2"); long[] counts = Lng.array(1, 2); statServiceClient.recordAll(Timer.timer().now(), names, counts); serviceBundle.flush(); triggerLatchWhen(o -> replicator.count.get() == 3); waitForLatch(20); ok = replicator.count.get() == 3 || die(replicator.count); }
@Test public void testWeSocketCallThatIsCrap() throws Exception { httpServer.sendWebSocketServerMessage(new WebSocketMessageBuilder().setMessage("CRAP") .setRemoteAddress("/crap/at/crap").setSender(new MockWebSocketSender()).build()); Sys.sleep(10); serviceServerImpl.flush(); Sys.sleep(10); waitForTrigger(20, o -> responseCounter == 1 && failureCounter == 1); ok |= responseCounter == 1 || die(); ok |= failureCounter == 1 || 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 test() { serviceBundle.addService(new MockService()); proxy = serviceBundle.createLocalProxy(MockServiceInterface.class, "mockService"); serviceBundle.startReturnHandlerProcessor(); proxy.method1(); proxy.clientProxyFlush(); Sys.sleep(1000); ok = callCount == 1 || die(); }
@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(); }