@ReadOnly @Override public T read(byte[] key) { byte[] read = kvTable.read(key); return decode(read); }
@Override public void run(DatasetContext context) throws Exception { KeyValueTable stateTable = context.getDataset(ETLRealtimeApplication.STATE_TABLE); byte[] stateBytes = stateTable.read(stateStoreKeyBytes); if (stateBytes != null) { SourceState state = GSON.fromJson(Bytes.toString(stateBytes), SourceState.class); currentState.setState(state); } } });
@ReadOnly @Override public T read(String key) { return decode(kvTable.read(Bytes.toBytes(key))); }
@Override public void apply() throws Exception { // verify that the value is now visible Assert.assertArrayEquals(VAL2, kvTable.read(KEY2)); } });
@Nullable public Long read(String key) { byte[] read = keyValueTable.read(key); return read == null ? null : Bytes.toLong(read); } }
@ReadOnly @Override public T read(String key) { return decode(kvTable.read(Bytes.toBytes(key))); }
@Override public void apply() throws Exception { KeyValueTable kvTable = datasetCache.getDataset(AppWithWorker.DATASET); Assert.assertEquals(AppWithWorker.RUN, Bytes.toString(kvTable.read(AppWithWorker.RUN))); Assert.assertEquals(AppWithWorker.INITIALIZE, Bytes.toString(kvTable.read(AppWithWorker.INITIALIZE))); Assert.assertEquals(AppWithWorker.STOP, Bytes.toString(kvTable.read(AppWithWorker.STOP))); } });
@GET @Path("ping/{key}") public void ping(HttpServiceRequest request, HttpServiceResponder responder, @PathParam("key") String key) throws IOException { responder.sendJson(Bytes.toString(table.read(key))); }
@Override public void apply() { Assert.assertNull(outputKvTable.read("a")); Assert.assertNull(outputKvTable.read("the")); Assert.assertNull(outputKvTable.read("an")); Assert.assertEquals(2, Bytes.toInt(outputKvTable.read("test"))); Assert.assertEquals(2, Bytes.toInt(outputKvTable.read("record"))); Assert.assertEquals(1, Bytes.toInt(outputKvTable.read("table"))); Assert.assertEquals(1, Bytes.toInt(outputKvTable.read("end"))); } }
@Override public void delete(final ProgramId serviceId) throws NotFoundException { Transactionals.execute(transactional, context -> { byte[] key = Bytes.toBytes(ServiceDiscoverable.getName(serviceId)); KeyValueTable kvTable = getRouteTable(context); if (kvTable.read(key) == null) { throw new NotFoundException(String.format("Route Config for Service %s was not found.", serviceId)); } kvTable.delete(key); }, NotFoundException.class); }
@Nullable public byte[] read(byte[] key) { track(getName(), "read"); return t.read(key); }
@GET @Path("read/{key}") public void readDataSet(HttpServiceRequest request, HttpServiceResponder responder, @PathParam("key") String key) throws IOException { byte[] value = table.read(key); if (value == null) { responder.sendError(404, "Table returned null for value: " + key); return; } responder.sendJson(Bytes.toString(value)); } }
@Override public void apply() { // the table should not have initialized=true Assert.assertEquals(expected, Bytes.toString(kvTable.read("initialized"))); } });
@Override public void run(DatasetContext context) throws Exception { byte[] value = table.read("completed"); completed.set((!(value == null || value.length != 1)) && Bytes.toBoolean(value)); table.increment(Bytes.toBytes("called"), 1L); } });
@GET @Path("/query") public void query(HttpServiceRequest request, HttpServiceResponder responder, @QueryParam("type") Record record) { long count = Bytes.toLong(records.read(Bytes.toBytes(record.getType().name()))); responder.sendString(200, Long.toString(count), Charsets.UTF_8); } }
@Override public void apply() { // the destroy() method should have recorded FAILED status in the kv table Assert.assertEquals(ProgramStatus.FAILED.name(), Bytes.toString(kvTable.read("status"))); } });
@Override public void apply() throws Exception { // write a swap, this should fail Assert.assertFalse(kvTable.compareAndSwap(KEY2, VAL1, VAL3)); Assert.assertArrayEquals(VAL2, kvTable.read(KEY2)); } });
private void checkOutputData(DataSetManager<KeyValueTable> manager) { KeyValueTable count = manager.get(); //read output and verify result byte[] val = count.read(Bytes.toBytes(TEST_STRING_1)); Assert.assertTrue(val != null); Assert.assertEquals(Bytes.toInt(val), TEST_STRING_1.length()); val = count.read(Bytes.toBytes(TEST_STRING_2)); Assert.assertTrue(val != null); Assert.assertEquals(Bytes.toInt(val), TEST_STRING_2.length()); }
@Override public void initialize() throws Exception { String inputPath = Bytes.toString(table.read(Bytes.toBytes("inputPath"))); String outputPath = Bytes.toString(table.read(Bytes.toBytes("outputPath"))); Job hadoopJob = getContext().getHadoopJob(); WordCount.configureJob(hadoopJob, inputPath, outputPath); hadoopJob.setPartitionerClass(SimplePartitioner.class); hadoopJob.setNumReduceTasks(2); hadoopJob.setGroupingComparatorClass(SimpleComparator.class); hadoopJob.setSortComparatorClass(SimpleComparator.class); hadoopJob.setCombinerKeyGroupingComparatorClass(SimpleComparator.class); } }
private void verifyDummyData(NamespaceId namespaceId, String datasetName) throws Exception { DataSetManager<KeyValueTable> outTableManager = getDataset(namespaceId.dataset(datasetName)); KeyValueTable outputTable = outTableManager.get(); Assert.assertEquals("world", Bytes.toString(outputTable.read("hello"))); }