@Test public void testReplyLong() { testReply(TestUtils.randomLong()); }
@Test public void testPublishLong() { testPublish(TestUtils.randomLong()); }
@Test public void testSendLong() { testSend(TestUtils.randomLong()); }
@Test public void testSlice1() throws Exception { Buffer buff = TestUtils.randomBuffer(100); Buffer sliced = buff.slice(); assertEquals(buff, sliced); long rand = TestUtils.randomLong(); sliced.setLong(0, rand); assertEquals(rand, buff.getLong(0)); buff.appendString(TestUtils.randomUnicodeString(100)); assertEquals(100, sliced.length()); }
@Test public void testSlice2() throws Exception { Buffer buff = TestUtils.randomBuffer(100); Buffer sliced = buff.slice(10, 20); for (int i = 0; i < 10; i++) { assertEquals(buff.getByte(10 + i), sliced.getByte(i)); } long rand = TestUtils.randomLong(); sliced.setLong(0, rand); assertEquals(rand, buff.getLong(10)); buff.appendString(TestUtils.randomUnicodeString(100)); assertEquals(10, sliced.length()); }
@Test public void testSendLong() { testSend(TestUtils.randomLong()); }
@Test public void testReplyLong() { testReply(TestUtils.randomLong()); }
@Test public void testPublishLong() { testPublish(TestUtils.randomLong()); }
@Test public void testSlice1() throws Exception { Buffer buff = TestUtils.randomBuffer(100); Buffer sliced = buff.slice(); assertEquals(buff, sliced); long rand = TestUtils.randomLong(); sliced.setLong(0, rand); assertEquals(rand, buff.getLong(0)); buff.appendString(TestUtils.randomUnicodeString(100)); assertEquals(100, sliced.length()); }
@Test public void testSlice2() throws Exception { Buffer buff = TestUtils.randomBuffer(100); Buffer sliced = buff.slice(10, 20); for (int i = 0; i < 10; i++) { assertEquals(buff.getByte(10 + i), sliced.getByte(i)); } long rand = TestUtils.randomLong(); sliced.setLong(0, rand); assertEquals(rand, buff.getLong(10)); buff.appendString(TestUtils.randomUnicodeString(100)); assertEquals(10, sliced.length()); }
public static KeyValue randomKeyValue() { return new KeyValue() .setKey(randomAlphaString(10)) .setValue(randomAlphaString(10)) .setSession(randomAlphaString(10)) .setCreateIndex(randomLong()) .setFlags(randomLong()) .setModifyIndex(randomLong()) .setLockIndex(randomLong()); }
public static Session randomSession() { return new Session() .setNode(randomAlphaString(10)) .setId(randomAlphaString(10)) .setLockDelay(randomLong()) .setCreateIndex(randomLong()) .setIndex(randomLong()) .setChecks(randomStringList(2)); }
@Test public void testCoordinateListCopy() { List<Coordinate> list = new ArrayList<>(); list.add(randomCoordinate()); list.add(randomCoordinate()); CoordinateList coordinateList = new CoordinateList() .setList(list) .setIndex(randomLong()); checkCoordinateList(coordinateList, new CoordinateList(coordinateList)); checkCoordinateList(coordinateList, new CoordinateList(coordinateList.toJson())); List<Coordinate> shuffled = new ArrayList<>(); shuffled.add(list.get(1)); shuffled.add(list.get(0)); CoordinateList coordsShuffled = new CoordinateList() .setList(shuffled) .setIndex(coordinateList.getIndex()); checkCoordinateList(coordinateList, coordsShuffled); }
@org.junit.Test public void testJsonOptions() { JsonObject json = new JsonObject(); long timeout = TestUtils.randomLong(); Boolean useEventLoop = randomBoolean(); String to = TestUtils.randomAlphaString(10); String at = TestUtils.randomAlphaString(10); String format = TestUtils.randomAlphaString(10); json.put("timeout", timeout); if (useEventLoop != null) { json.put("useEventLoop", useEventLoop); } json.put("reporters", new JsonArray(). add(new JsonObject(). put("to", to). put("at", at). put("format", format))); TestOptions options = new TestOptions(json); assertEquals(timeout, options.getTimeout()); assertEquals(useEventLoop, options.isUseEventLoop()); assertEquals(1, options.getReporters().size()); assertEquals(to, options.getReporters().get(0).getTo()); assertEquals(format, options.getReporters().get(0).getFormat()); } }
@Test public void testKeyValueListCopy() { List<KeyValue> list = new ArrayList<>(); list.add(randomKeyValue()); list.add(randomKeyValue()); KeyValueList kvList = new KeyValueList() .setList(list) .setIndex(randomLong()); checkKeyValueList(kvList, new KeyValueList(kvList)); checkKeyValueList(kvList, new KeyValueList(kvList.toJson())); List<KeyValue> shuffled = new ArrayList<>(); shuffled.add(list.get(1)); shuffled.add(list.get(0)); KeyValueList kvShuffled = new KeyValueList() .setList(shuffled) .setIndex(kvList.getIndex()); checkKeyValueList(kvList, kvShuffled); }
@org.junit.Test public void testTestOptions() { TestOptions options = new TestOptions(); assertEquals(TestOptions.DEFAULT_TIMEOUT, options.getTimeout()); assertEquals(TestOptions.DEFAULT_USE_EVENT_LOOP, options.isUseEventLoop()); assertEquals(Collections.<ReportOptions>emptyList(), options.getReporters()); long timeout = TestUtils.randomLong(); Boolean useEventLoop = randomBoolean(); assertSame(options, options.setTimeout(timeout)); assertSame(options, options.setUseEventLoop(useEventLoop)); assertEquals(timeout, options.getTimeout()); assertEquals(useEventLoop, options.isUseEventLoop()); List<ReportOptions> reporters = new ArrayList<>(); ReportOptions reporter1 = new ReportOptions(); reporters.add(reporter1); assertSame(options, options.setReporters(reporters)); assertEquals(reporters, options.getReporters()); ReportOptions reporter2 = new ReportOptions(); assertSame(options, options.addReporter(reporter2)); assertEquals(reporters, options.getReporters()); assertEquals(2, reporters.size()); assertEquals(Arrays.asList(reporter1, reporter2), reporters); }
@org.junit.Test public void testCopyOptions() { TestOptions options = new TestOptions(); long timeout = TestUtils.randomLong(); Boolean useEventLoop = randomBoolean(); String to = TestUtils.randomAlphaString(10); String at = TestUtils.randomAlphaString(10); String format = TestUtils.randomAlphaString(10); ReportOptions reporter = new ReportOptions().setTo(to).setFormat(format); options.setUseEventLoop(useEventLoop).setTimeout(timeout).addReporter(reporter); TestOptions copy = new TestOptions(options); options.setTimeout(TestUtils.randomLong()); options.setUseEventLoop(randomBoolean()); reporter.setTo(TestUtils.randomAlphaString(10)); reporter.setFormat(TestUtils.randomAlphaString(10)); options.getReporters().clear(); assertEquals(timeout, copy.getTimeout()); assertEquals(useEventLoop, copy.isUseEventLoop()); assertEquals(1, copy.getReporters().size()); assertEquals(to, copy.getReporters().get(0).getTo()); assertEquals(format, copy.getReporters().get(0).getFormat()); }
@Test public void writeClientHaveFullAccessToOneValue(TestContext tc) { String key = randomFooBarAlpha(); String value = randomAlphaString(10); KeyValueOptions opts = new KeyValueOptions().setFlags(randomLong()); ctx.writeClient() .putValueWithOptions(key, value, opts, tc.asyncAssertSuccess(b -> { tc.assertTrue(b); ctx.readClient().getValue(key, tc.asyncAssertSuccess(pair -> { tc.assertEquals(key, pair.getKey()); tc.assertEquals(value, pair.getValue()); assertEquals(opts.getFlags(), pair.getFlags()); ctx.writeClient().deleteValue(key, tc.asyncAssertSuccess()); })); })); }