/** * Test compatability between version 4.1.0 and the current version. * * <p>A current client running message filter would fail on 4.1.0 hub servers. */ @Test(timeout = 60000) public void testClientMessageFilterCompat410() throws Exception { ByteString topic = ByteString.copyFromUtf8("TestUpdateMessageBoundCompat410"); ByteString subid = ByteString.copyFromUtf8("mysub"); // start bookkeeper BookKeeperCluster410 bkc410 = new BookKeeperCluster410(3); bkc410.start(); int port = PortManager.nextFreePort(); int sslPort = PortManager.nextFreePort(); // start hub server 410 Server410 s410 = new Server410(zkUtil.getZooKeeperConnectString(), port, sslPort); s410.start(); ClientCurrent ccur = new ClientCurrent("localhost:" + port + ":" + sslPort); ccur.subscribe(topic, subid); ccur.closeSubscription(topic, subid); ccur.publishInts(topic, 0, 100); try { ccur.receiveNumModM(topic, subid, 0, 50, 2); fail("client-side filter could not run on 4.1.0 hub server"); } catch (Exception e) { logger.info("Should fail to run client-side message filter on 4.1.0 hub server.", e); ccur.closeSubscription(topic, subid); } // stop 410 server s410.stop(); // stop bookkeeper cluster bkc410.stop(); }
private static List<ReadRowsResponse> createResponses() { List<ReadRowsResponse> responses = new ArrayList<>(1); for (int i = 0; i < 1; i++) { String rowKey = String.format("rowKey-%s", i); byte[] value = RandomStringUtils.randomAlphanumeric(10000).getBytes(); Preconditions.checkArgument( !Strings.isNullOrEmpty("Family1"), "Family name may not be null or empty"); Family.Builder familyBuilder = Family.newBuilder().setName("Family1"); Column.Builder columnBuilder = Column.newBuilder(); columnBuilder.setQualifier(ByteString.copyFromUtf8("Qaulifier")); if (value != null) { Cell.Builder cellBuilder = Cell.newBuilder(); cellBuilder.setTimestampMicros(0L); cellBuilder.setValue(ByteString.copyFrom(value)); columnBuilder.addCells(cellBuilder); } familyBuilder.addColumns(columnBuilder); Chunk contentChunk = Chunk.newBuilder().setRowContents(familyBuilder).build(); Chunk rowCompleteChunk = Chunk.newBuilder().setCommitRow(true).build(); ReadRowsResponse response = ReadRowsResponse.newBuilder() .addChunks(contentChunk) .addChunks(rowCompleteChunk) .setRowKey(ByteString.copyFromUtf8(rowKey)) .build(); responses.add(response); } return responses; }
/** * Test compatability between version 4.1.0 and the current version. * * <p>Server side throttling does't work when current client connects to old version server. */ @Test(timeout = 60000) public void testServerSideThrottleCompat410() throws Exception { ByteString topic = ByteString.copyFromUtf8("TestServerSideThrottleCompat410"); ByteString subid = ByteString.copyFromUtf8("mysub"); // start bookkeeper BookKeeperCluster410 bkc410 = new BookKeeperCluster410(3); bkc410.start(); int port = PortManager.nextFreePort(); int sslPort = PortManager.nextFreePort(); // start hub server 410 Server410 s410 = new Server410(zkUtil.getZooKeeperConnectString(), port, sslPort); s410.start(); ClientCurrent ccur = new ClientCurrent(false, "localhost:" + port + ":" + sslPort); ccur.throttleX41(topic, subid, 10); ccur.close(); // stop 410 server s410.stop(); // stop bookkeeper cluster bkc410.stop(); }
@Override public boolean runCmd(String[] args) throws Exception { if (args.length < 7) { return false; } String topicPrefix = args[1]; int startTopic = Integer.parseInt(args[2]); int endTopic = Integer.parseInt(args[3]); String subPrefix = args[4]; int startSub = Integer.parseInt(args[5]); int endSub = Integer.parseInt(args[6]); if (startTopic > endTopic || endSub < startSub) { return false; } for (int i = startTopic; i <= endTopic; i++) { ByteString topic = ByteString.copyFromUtf8(topicPrefix + i); try { for (int j = startSub; j <= endSub; j++) { ByteString sub = ByteString.copyFromUtf8(subPrefix + j); subscriber.subscribe(topic, sub, CreateOrAttach.CREATE_OR_ATTACH); subscriber.unsubscribe(topic, sub); } System.out.println("RMSUB " + topic.toStringUtf8() + " DONE"); } catch (Exception e) { System.err.println("RMSUB " + topic.toStringUtf8() + " FAILED"); e.printStackTrace(); } } return true; }
@Override public boolean runCmd(String[] args) throws Exception { if (args.length < 3) { return false; } ByteString topic = ByteString.copyFromUtf8(args[1]); StringBuilder sb = new StringBuilder(); for (int i = 2; i < args.length; i++) { sb.append(args[i]); if (i != args.length - 1) { sb.append(' '); } } ByteString msgBody = ByteString.copyFromUtf8(sb.toString()); Message msg = Message.newBuilder().setBody(msgBody).build(); try { publisher.publish(topic, msg); System.out.println("PUB DONE"); } catch (Exception e) { System.err.println("PUB FAILED"); e.printStackTrace(); } return true; }
/** * Test Increment Mutate conversions. * * @throws IOException */ @Test public void testIncrement() throws IOException { Mutate.Builder mutateBuilder = Mutate.newBuilder(); mutateBuilder.setRow(ByteString.copyFromUtf8("row")); mutateBuilder.setMutateType(MutateType.INCREMENT); ColumnValue.Builder valueBuilder = ColumnValue.newBuilder(); valueBuilder.setFamily(ByteString.copyFromUtf8("f1")); QualifierValue.Builder qualifierBuilder = QualifierValue.newBuilder(); qualifierBuilder.setQualifier(ByteString.copyFromUtf8("c1")); qualifierBuilder.setValue(ByteString.copyFrom(Bytes.toBytes(11L))); valueBuilder.addQualifierValue(qualifierBuilder.build()); qualifierBuilder.setQualifier(ByteString.copyFromUtf8("c2")); qualifierBuilder.setValue(ByteString.copyFrom(Bytes.toBytes(22L))); valueBuilder.addQualifierValue(qualifierBuilder.build()); mutateBuilder.addColumnValue(valueBuilder.build()); Mutate proto = mutateBuilder.build(); // default fields assertEquals(true, proto.getWriteToWAL()); // set the default value for equal comparison mutateBuilder = Mutate.newBuilder(proto); mutateBuilder.setWriteToWAL(true); Increment increment = ProtobufUtil.toIncrement(proto); assertEquals(mutateBuilder.build(), ProtobufUtil.toMutate(increment)); }
/** * Test basic Get conversions. * * @throws IOException */ @Test public void testGet() throws IOException { ClientProtos.Get.Builder getBuilder = ClientProtos.Get.newBuilder(); getBuilder.setRow(ByteString.copyFromUtf8("row")); Column.Builder columnBuilder = Column.newBuilder(); columnBuilder.setFamily(ByteString.copyFromUtf8("f1")); columnBuilder.addQualifier(ByteString.copyFromUtf8("c1")); columnBuilder.addQualifier(ByteString.copyFromUtf8("c2")); getBuilder.addColumn(columnBuilder.build()); columnBuilder.clear(); columnBuilder.setFamily(ByteString.copyFromUtf8("f2")); getBuilder.addColumn(columnBuilder.build()); ClientProtos.Get proto = getBuilder.build(); // default fields assertEquals(1, proto.getMaxVersions()); assertEquals(true, proto.getCacheBlocks()); // set the default value for equal comparison getBuilder = ClientProtos.Get.newBuilder(proto); getBuilder.setMaxVersions(1); getBuilder.setCacheBlocks(true); Get get = ProtobufUtil.toGet(proto); assertEquals(getBuilder.build(), ProtobufUtil.toGet(get)); }
@Override public boolean runCmd(String[] args) throws Exception { if (args.length < 4) { return false; } long lastConsumedId = 0; SubscriptionData subData = admin.getSubscription(ByteString.copyFromUtf8(args[1]), ByteString.copyFromUtf8(args[2])); if (null == subData) { System.err.println( "Failed to read subscription for topic: " + args[1] + " subscriber: " + args[2]); return true; } lastConsumedId = subData.getState().getMsgId().getLocalComponent(); long numMessagesToConsume = Long.parseLong(args[3]); long idToConsumed = lastConsumedId + numMessagesToConsume; System.out.println( "Try to move subscriber(" + args[2] + ") consume ptr of topic(" + args[1] + ") from " + lastConsumedId + " to " + idToConsumed); MessageSeqId consumeId = MessageSeqId.newBuilder().setLocalComponent(idToConsumed).build(); ByteString topic = ByteString.copyFromUtf8(args[1]); ByteString subId = ByteString.copyFromUtf8(args[2]); try { subscriber.consume(topic, subId, consumeId); } catch (Exception e) { System.err.println("CONSUME FAILED"); } return true; }
public void testPushingLotsOfData() throws IOException { RiakClient riak = new RiakClient("127.0.0.1", RiakConnection.DEFAULT_RIAK_PB_PORT); long before = System.currentTimeMillis(); byte[] val = new byte[419]; ByteString value = ByteString.copyFrom(val); for (int i = 0; i < 100; i++) { long before2 = System.currentTimeMillis(); String cpr = "" + (1000000000 + i); ByteString cpr_key = ByteString.copyFromUtf8(cpr); for (int rid = 0; rid < 1000; rid++) { ByteString rid_key = ByteString.copyFromUtf8("" + (200000 + i)); RiakObject ro = new RiakObject(cpr_key, rid_key, value); riak.store(ro); } long after2 = System.currentTimeMillis(); System.out.println("" + i + " x 1000 INSERTS: " + (after2 - before2) + "ms"); } long after = System.currentTimeMillis(); System.out.println("TOTAL TIME: " + (1.0 * (after - before) / 1000.0) + "s"); }
@Test public void testNullClientMessageFilter() throws Exception { ByteString topic = ByteString.copyFromUtf8("TestNullClientMessageFilter"); ByteString subid = ByteString.copyFromUtf8("mysub"); subscriber.subscribe(topic, subid, CreateOrAttach.CREATE_OR_ATTACH); try { subscriber.startDeliveryWithFilter(topic, subid, null, new ModMessageFilter()); fail("Should fail start delivery with filter using null message handler."); } catch (NullPointerException npe) { } try { subscriber.startDeliveryWithFilter( topic, subid, new MessageHandler() { public void deliver( ByteString topic, ByteString subscriberId, Message msg, Callback<Void> callback, Object context) { // do nothing } }, null); fail("Should fail start delivery with filter using null message filter."); } catch (NullPointerException npe) { } }
private byte[] writePartialFile(DataOutputStream out) throws IOException { MessageQueue.Message m1 = MessageQueue.Message.newBuilder() .setTime(1) .setPayload(ByteString.copyFromUtf8("test 1")) .build(); out.writeInt(m1.getSerializedSize()); m1.writeTo(out); MessageQueue.Message m2 = MessageQueue.Message.newBuilder() .setTime(2) .setPayload(ByteString.copyFromUtf8("test 2")) .build(); out.writeInt(m2.getSerializedSize()); m2.writeTo(out); MessageQueue.Message m3 = MessageQueue.Message.newBuilder() .setTime(3) .setPayload(ByteString.copyFromUtf8("test 3")) .build(); byte[] bytes = m3.toByteArray(); out.writeInt(bytes.length); out.write(bytes, 0, 6); out.flush(); return bytes; }
/** * Test compatability between version 4.1.0 and the current version. * * <p>A current server could read subscription data recorded by 4.1.0 server. */ @Test(timeout = 60000) public void testSubscriptionDataCompat410() throws Exception { ByteString topic = ByteString.copyFromUtf8("TestCompat410"); ByteString sub410 = ByteString.copyFromUtf8("sub410"); ByteString subcur = ByteString.copyFromUtf8("subcur"); // start bookkeeper 410 BookKeeperCluster410 bkc410 = new BookKeeperCluster410(3); bkc410.start(); int port = PortManager.nextFreePort(); int sslPort = PortManager.nextFreePort(); // start 410 server Server410 s410 = new Server410(zkUtil.getZooKeeperConnectString(), port, sslPort); s410.start(); Client410 c410 = new Client410("localhost:" + port + ":" + sslPort); c410.subscribe(topic, sub410); c410.closeSubscription(topic, sub410); Thread.sleep(1000); // give server time to run disconnect logic (BOOKKEEPER-513) ClientCurrent ccur = new ClientCurrent("localhost:" + port + ":" + sslPort); ccur.subscribe(topic, subcur); ccur.closeSubscription(topic, subcur); // publish messages using old client c410.publishInts(topic, 0, 10); // stop 410 server s410.stop(); // start 420 server Server420 s420 = new Server420(zkUtil.getZooKeeperConnectString(), port, sslPort); s420.start(); c410.subscribe(topic, sub410); c410.receiveInts(topic, sub410, 0, 10); ccur.subscribe(topic, subcur); ccur.receiveInts(topic, subcur, 0, 10); // publish messages using current client ccur.publishInts(topic, 10, 10); c410.receiveInts(topic, sub410, 10, 10); ccur.receiveInts(topic, subcur, 10, 10); // stop 420 server s420.stop(); c410.close(); ccur.close(); // stop bookkeeper cluster bkc410.stop(); }
@Test public void testClientSideMessageFilter() throws Exception { ByteString topic = ByteString.copyFromUtf8("TestClientMessageFilter"); ByteString subid = ByteString.copyFromUtf8("mysub"); subscriber.subscribe(topic, subid, CreateOrAttach.CREATE_OR_ATTACH); subscriber.closeSubscription(topic, subid); publishNums(topic, 0, 100, 2); receiveNumModM(topic, subid, null, new ModMessageFilter(), 0, 50, 2, true); }
/** Helper function to generate KV test data. */ private List<KV<ByteString, ByteString>> generateTableData(int numRows) { List<KV<ByteString, ByteString>> testData = new ArrayList<>(numRows); for (int i = 0; i < numRows; ++i) { ByteString key = ByteString.copyFromUtf8(String.format("key%09d", i)); ByteString value = ByteString.copyFromUtf8(String.format("value%09d", i)); testData.add(KV.of(key, value)); } return testData; }
private RiakPB.RpbCommitHook convertHook(Function hook) { RiakPB.RpbCommitHook.Builder builder = RiakPB.RpbCommitHook.newBuilder(); RiakPB.RpbModFun.Builder mfBuilder = RiakPB.RpbModFun.newBuilder(); if (hook.isJavascript()) { builder.setName(ByteString.copyFromUtf8(hook.getName())); } else { mfBuilder.setModule(ByteString.copyFromUtf8(hook.getModule())); mfBuilder.setFunction(ByteString.copyFromUtf8(hook.getFunction())); builder.setModfun(mfBuilder); } return builder.build(); }
@Test public void tags() throws Exception { myWallet.setTag("foo", ByteString.copyFromUtf8("bar")); assertEquals("bar", myWallet.getTag("foo").toStringUtf8()); myWallet = roundTrip(myWallet); assertEquals("bar", myWallet.getTag("foo").toStringUtf8()); }
@Test public void testGetBigDecimal() throws Exception { List<Query.Type> types = Arrays.asList(Query.Type.DECIMAL); for (Query.Type type : types) { try (Cursor cursor = new SimpleCursor( QueryResult.newBuilder() .addFields(Field.newBuilder().setName("col1").setType(type).build()) .addFields(Field.newBuilder().setName("null").setType(type).build()) .addRows( Query.Row.newBuilder() .addLengths("1234.56789".length()) .addLengths(-1) // SQL NULL .setValues(ByteString.copyFromUtf8("1234.56789"))) .build())) { Row row = cursor.next(); Assert.assertNotNull(row); Assert.assertEquals( new BigDecimal(BigInteger.valueOf(123456789), 5), row.getBigDecimal("col1")); Assert.assertFalse(row.wasNull()); Assert.assertEquals(null, row.getBigDecimal("null")); Assert.assertTrue(row.wasNull()); } } }
@Test public void testGetBytes() throws Exception { List<Field.Type> types = Arrays.asList( Field.Type.TYPE_VARCHAR, Field.Type.TYPE_BIT, Field.Type.TYPE_TINY_BLOB, Field.Type.TYPE_MEDIUM_BLOB, Field.Type.TYPE_LONG_BLOB, Field.Type.TYPE_BLOB, Field.Type.TYPE_VAR_STRING, Field.Type.TYPE_STRING, Field.Type.TYPE_GEOMETRY); for (Field.Type type : types) { try (Cursor cursor = new SimpleCursor( QueryResult.newBuilder() .addFields(Field.newBuilder().setName("col0").setType(type).build()) .addRows(Row.newBuilder().addValues(ByteString.copyFromUtf8("hello world"))) .build())) { cursor.next(); Assert.assertArrayEquals("hello world".getBytes("UTF-8"), cursor.getBytes("col0")); } } }
@Test public void testChangeServerSideMessageFilter() throws Exception { ByteString topic = ByteString.copyFromUtf8("TestChangeMessageFilter"); ByteString subid = ByteString.copyFromUtf8("mysub"); subscriber.subscribe(topic, subid, CreateOrAttach.CREATE_OR_ATTACH); subscriber.closeSubscription(topic, subid); publishNums(topic, 0, 100, 3); receiveNumModM(topic, subid, ModMessageFilter.class.getName(), null, 0, 50, 2, false); receiveNumModM(topic, subid, ModMessageFilter.class.getName(), null, 0, 25, 4, false); receiveNumModM(topic, subid, HeaderMessageFilter.class.getName(), null, 0, 33, 3, true); publishNums(topic, 200, 100, 7); receiveNumModM(topic, subid, HeaderMessageFilter.class.getName(), null, 200, 14, 7, true); }
@Override public boolean runCmd(String[] args) throws Exception { if (args.length < 4) { return false; } ByteString topic = ByteString.copyFromUtf8(args[1]); ByteString subId = ByteString.copyFromUtf8(args[2]); long msgId = Long.parseLong(args[3]); MessageSeqId consumeId = MessageSeqId.newBuilder().setLocalComponent(msgId).build(); try { subscriber.consume(topic, subId, consumeId); } catch (Exception e) { System.err.println("CONSUMETO FAILED"); } return true; }
@Test public void testMoreUnknown() throws Exception { UnknownFieldSet unknownGroupLevel2 = UnknownFieldSet.newBuilder() .addField(16, UnknownFieldSet.Field.newBuilder().addVarint(566667).build()) .build(); UnknownFieldSet unknownGroup = UnknownFieldSet.newBuilder() .addField(11, UnknownFieldSet.Field.newBuilder().addVarint(566667).build()) .addField(15, UnknownFieldSet.Field.newBuilder().addGroup(unknownGroupLevel2).build()) .build(); ByteString bs = ByteString.copyFromUtf8("testUnknown"); OneString data = OneString.newBuilder() .setUnknownFields( UnknownFieldSet.newBuilder() .addField(5, UnknownFieldSet.Field.newBuilder().addFixed32(999).build()) .addField(6, UnknownFieldSet.Field.newBuilder().addGroup(unknownGroup).build()) .addField(7, UnknownFieldSet.Field.newBuilder().addLengthDelimited(bs).build()) .build()) .setData("12345") .build(); String javaText = formatter.printToString(data); // System.out.println(javaText); OneString.Builder builder = OneString.newBuilder(); formatter.merge(TextUtils.toInputStream(javaText), builder); assertEquals(data.getData(), builder.build().getData()); }
/** * Associate a Search Index. This only applies if Yokozuna is enabled in Riak v2.0. * * @param indexName The name of the search index to use. * @return a reference to this object. */ public T withSearchIndex(String indexName) { if (null == indexName || indexName.length() == 0) { throw new IllegalArgumentException("Index name cannot be null or zero length"); } propsBuilder.setSearchIndex(ByteString.copyFromUtf8(indexName)); return self(); }
@Override public boolean runCmd(String[] args) throws Exception { if (args.length < 3) { return false; } ByteString topic = ByteString.copyFromUtf8(args[1]); ByteString sudId = ByteString.copyFromUtf8(args[2]); try { subscriber.stopDelivery(topic, sudId); subscriber.closeSubscription(topic, sudId); } catch (Exception e) { System.err.println("CLOSESUB FAILED"); } return true; }
/* * (non-Javadoc) * * @see * com.basho.riak.client.raw.RawClient#fetchBucketKeys(java.lang.String) */ public Iterable<String> listKeys(String bucketName) throws IOException { if (bucketName == null || bucketName.trim().equals("")) { throw new IllegalArgumentException("bucketName cannot be null, empty or all whitespace"); } final KeySource keySource = client.listKeys(ByteString.copyFromUtf8(bucketName)); final Iterator<String> i = new Iterator<String>() { private final Iterator<ByteString> delegate = keySource.iterator(); public boolean hasNext() { return delegate.hasNext(); } public String next() { return nullSafeToStringUtf8(delegate.next()); } public void remove() { delegate.remove(); } }; return new Iterable<String>() { public Iterator<String> iterator() { return i; } }; }
@Test public void testGetInt() throws Exception { List<Query.Type> types = Arrays.asList( Query.Type.INT8, Query.Type.UINT8, Query.Type.INT16, Query.Type.UINT16, Query.Type.INT24, Query.Type.UINT24, Query.Type.INT32); for (Query.Type type : types) { try (Cursor cursor = new SimpleCursor( QueryResult.newBuilder() .addFields(Field.newBuilder().setName("col1").setType(type).build()) .addFields(Field.newBuilder().setName("null").setType(type).build()) .addRows( Query.Row.newBuilder() .addLengths("12345".length()) .addLengths(-1) // SQL NULL .setValues(ByteString.copyFromUtf8("12345"))) .build())) { Row row = cursor.next(); Assert.assertNotNull(row); Assert.assertEquals(12345, row.getInt("col1")); Assert.assertFalse(row.wasNull()); Assert.assertEquals(0, row.getInt("null")); Assert.assertTrue(row.wasNull()); Assert.assertEquals(null, row.getObject("null", Integer.class)); Assert.assertTrue(row.wasNull()); } } }
/** * Set the backend used by this bucket. Only applies when using {@code riak_kv_multi_backend} in * Riak. * * @param backend the name of the backend to use. * @return a reference to this object. */ public T withBackend(String backend) { if (null == backend || backend.length() == 0) { throw new IllegalArgumentException("Backend can not be null or zero length"); } propsBuilder.setBackend(ByteString.copyFromUtf8(backend)); return self(); }
@Test public void testGetDate() throws Exception { List<Query.Type> types = Arrays.asList(Query.Type.DATE); for (Query.Type type : types) { try (Cursor cursor = new SimpleCursor( QueryResult.newBuilder() .addFields(Field.newBuilder().setName("col1").setType(type).build()) .addFields(Field.newBuilder().setName("null").setType(type).build()) .addRows( Query.Row.newBuilder() .addLengths("2008-01-02".length()) .addLengths(-1) // SQL NULL .setValues(ByteString.copyFromUtf8("2008-01-02"))) .build())) { Row row = cursor.next(); Assert.assertNotNull(row); Assert.assertEquals(Date.valueOf("2008-01-02"), row.getObject("col1")); Assert.assertEquals(Date.valueOf("2008-01-02"), row.getDate("col1")); Assert.assertEquals(new Date(1199232000000L), row.getDate("col1", GMT)); Assert.assertFalse(row.wasNull()); Assert.assertEquals(null, row.getDate("null")); Assert.assertTrue(row.wasNull()); } } }
@Test public void testGetTimestamp() throws Exception { List<Query.Type> types = Arrays.asList(Query.Type.DATETIME, Query.Type.TIMESTAMP); for (Query.Type type : types) { try (Cursor cursor = new SimpleCursor( QueryResult.newBuilder() .addFields(Field.newBuilder().setName("col1").setType(type).build()) .addFields(Field.newBuilder().setName("null").setType(type).build()) .addRows( Query.Row.newBuilder() .addLengths("2008-01-02 14:15:16.123456".length()) .addLengths(-1) // SQL NULL .setValues(ByteString.copyFromUtf8("2008-01-02 14:15:16.123456"))) .build())) { Row row = cursor.next(); Assert.assertNotNull(row); Assert.assertEquals(Timestamp.valueOf("2008-01-02 14:15:16.123456"), row.getObject("col1")); Assert.assertEquals( Timestamp.valueOf("2008-01-02 14:15:16.123456"), row.getTimestamp("col1")); Timestamp ts = new Timestamp(1199283316000L); ts.setNanos(123456000); Assert.assertEquals(ts, row.getTimestamp("col1", GMT)); Assert.assertFalse(row.wasNull()); Assert.assertEquals(null, row.getTimestamp("null")); Assert.assertTrue(row.wasNull()); } } }
@Test public void testGetBytes() throws Exception { List<Query.Type> types = Arrays.asList( Query.Type.TEXT, Query.Type.BLOB, Query.Type.VARCHAR, Query.Type.VARBINARY, Query.Type.CHAR, Query.Type.BINARY, Query.Type.BIT); for (Query.Type type : types) { try (Cursor cursor = new SimpleCursor( QueryResult.newBuilder() .addFields(Field.newBuilder().setName("col1").setType(type).build()) .addFields(Field.newBuilder().setName("null").setType(type).build()) .addRows( Query.Row.newBuilder() .addLengths("hello world".length()) .addLengths(-1) // SQL NULL .setValues(ByteString.copyFromUtf8("hello world"))) .build())) { Row row = cursor.next(); Assert.assertNotNull(row); Assert.assertArrayEquals("hello world".getBytes("UTF-8"), row.getBytes("col1")); Assert.assertFalse(row.wasNull()); Assert.assertEquals(null, row.getBytes("null")); Assert.assertTrue(row.wasNull()); } } }
@Test(dependsOnGroups = "example.ipc.server") public void clientRPC() throws Exception { RPC.ClientRPC client = RPC.getClientRPC(socketAddress); GetRequest request = GetRequest.newBuilder().setRow(ByteString.copyFromUtf8("row1")).build(); Deferred<GetResponse> response = client.getData(request); GetResponse data = response.join(); System.out.println(data); Deferred<GetResponse> deferred = client.getData(request); deferred .addCallback( new Callback<Object, GetResponse>() { public Object call(final GetResponse getResponse) throws Exception { System.out.println(getResponse); return null; } }) .addErrback( new Callback<Object, Object>() { public Object call(final Object o) throws Exception { System.err.println("ERROR: " + o); return null; } }); }