@Override public String call() throws Exception { return executor.execute( new Callable<String>() { @Override public String call() throws Exception { KeyValueTable kvTable = datasetCache.getDataset(AppWithWorker.DATASET); return Bytes.toString(kvTable.read(AppWithWorker.RUN)); } }); } }, 5, TimeUnit.SECONDS);
private void writeFact(final Fact fact) throws InterruptedException, TransactionFailureException { txnl.execute(new TransactionExecutor.Subroutine() { @Override public void apply() throws Exception { long ts = fact.getTs(); byte[] srcTag = Bytes.toBytes(fact.getDimensions().get(SRC_DEVICE_ID_TAG)); byte[] destTag = Bytes.toBytes(fact.getDimensions().get(DEST_DEVICE_ID_TAG)); if (fact.getDimensions().get(SRC_DEVICE_ID_TAG).equals("1.1.1.1")) { table.write(new TimeseriesTable.Entry(ALL_KEY, Bytes.toBytes(fact.getDimensions().get(DST_TAG)), ts)); } else { table.write(new TimeseriesTable.Entry(ALL_KEY, Bytes.toBytes(fact.getDimensions().get(DST_TAG)), ts, srcTag, destTag)); } } }); }
private void executeDelete(final TriggerKey triggerKey) { try { factory.createExecutor(ImmutableList.of((TransactionAware) table)) .execute(() -> removeTrigger(table, triggerKey)); } catch (Throwable th) { throw Throwables.propagate(th); } }
private void executeDelete(final JobKey jobKey) { try { factory.createExecutor(ImmutableList.of((TransactionAware) table)) .execute(() -> removeJob(table, jobKey)); } catch (Throwable t) { throw Throwables.propagate(t); } }
private void executeDelete(final JobKey jobKey) { try { factory.createExecutor(ImmutableList.of((TransactionAware) table)) .execute(() -> removeJob(table, jobKey)); } catch (Throwable t) { throw Throwables.propagate(t); } }
private void executeDelete(final TriggerKey triggerKey) { try { factory.createExecutor(ImmutableList.of((TransactionAware) table)) .execute(() -> removeTrigger(table, triggerKey)); } catch (Throwable th) { throw Throwables.propagate(th); } }
@After public void tearDown() throws Exception { txExecutor.execute(new TransactionExecutor.Subroutine() { @Override public void apply() throws Exception { for (Job job : getAllJobs(jobQueue, true)) { jobQueue.deleteJob(job); } } }); }
private void fillTestInputData(TransactionExecutorFactory txExecutorFactory, final TimeseriesTable table, final boolean withBadData) throws TransactionFailureException, InterruptedException { TransactionExecutor executor = Transactions.createTransactionExecutor(txExecutorFactory, table); executor.execute(new TransactionExecutor.Subroutine() { @Override public void apply() { fillTestInputData(table, withBadData); } }); }
private void writeRunRecordMeta(RunRecordMeta runRecordMeta, long timestampInMillis) throws InterruptedException, TransactionFailureException { heartBeatTxnl.execute(() -> programHeartbeatDataset.writeRunRecordMeta(runRecordMeta, timestampInMillis)); }
/** * writes heart beat messages starting from startTime + interval up to endTime, each heartbeat separated by interval */ private void setUpProgramHeartBeats(RunRecordMeta runRecordMeta, long startTime, long endTime, long interval, TransactionExecutor txnl, ProgramHeartbeatDataset programHeartbeatDataset) throws InterruptedException, TransactionFailureException { txnl.execute(() -> { for (long time = startTime + interval; time < endTime; time += interval) { programHeartbeatDataset.writeRunRecordMeta(runRecordMeta, time); } }); }
@Test(expected = TransactionFailureException.class) public void testInvalidTimeRangeCondition() throws Exception { TransactionExecutor txnl = dsFrameworkUtil.newTransactionExecutor(table); txnl.execute(new TransactionExecutor.Subroutine() { @Override public void apply() throws Exception { long ts = System.currentTimeMillis(); table.read(Bytes.toBytes("any"), ts, ts - 100); } }); }
@Test public void test() throws Exception { final long now = System.currentTimeMillis(); sendData(now); // verify txnl.execute(new TransactionExecutor.Subroutine() { @Override public void apply() throws Exception { testScan(now); testNoRow(now); testFilter(now); testNoTagMatch(now); testReadEntryWithoutTag(now); } }); }
private void heartbeatDatasetStatusCheck(long startTime, ProgramRunStatus expectedStatus) throws InterruptedException, ExecutionException, TimeoutException { Tasks.waitFor(expectedStatus, () -> heartBeatTxnl.execute(() -> { Collection<RunRecordMeta> runRecordMetas = // programHeartbeatDataset uses seconds for timeunit for recording runrecords programHeartbeatDataset.scan( TimeUnit.MILLISECONDS.toSeconds(startTime), TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()), ImmutableSet.of(NamespaceId.DEFAULT.getNamespace())); if (runRecordMetas.size() == 0) { return null; } Assert.assertEquals(1, runRecordMetas.size()); return runRecordMetas.iterator().next().getStatus(); }), 10, TimeUnit.SECONDS); }
private List<ProgramRunId> addProgramCount(TransactionExecutor txnl, AppMetadataStore store, ProgramId programId, int count) throws Exception { List<ProgramRunId> runIds = new ArrayList<>(); for (int i = 0; i < count; i++) { RunId runId = RunIds.generate(i * 1000); ProgramRunId run = programId.run(runId); runIds.add(run); txnl.execute(() -> { recordProvisionAndStart(run, store); }); } return runIds; }
private void testInputConfigurationFailure(Map<String, String> arguments, final String why) throws Exception { final TimePartitionedFileSet dataset = dsFrameworkUtil.getInstance(TPFS_INSTANCE, arguments); TransactionAware txAwareDataset = (TransactionAware) dataset; dsFrameworkUtil.newInMemoryTransactionExecutor(txAwareDataset).execute(new TransactionExecutor.Subroutine() { @Override public void apply() throws Exception { try { dataset.getInputFormatConfiguration(); Assert.fail("getInputFormatConfiguration should fail " + why); } catch (Exception e) { // expected } }}); }
@Test public void testValidTimeRangesAreAllowed() throws Exception { TransactionExecutor txnl = dsFrameworkUtil.newTransactionExecutor(table); txnl.execute(new TransactionExecutor.Subroutine() { @Override public void apply() throws Exception { long ts = System.currentTimeMillis(); Iterator<TimeseriesTable.Entry> temp = table.read(Bytes.toBytes("any"), ts, ts); Assert.assertFalse(temp.hasNext()); temp = table.read(Bytes.toBytes("any"), ts, ts + 100); Assert.assertFalse(temp.hasNext()); } }); }
private void testInputConfiguration(Map<String, String> arguments, final String expectedPath) throws Exception { final TimePartitionedFileSet dataset = dsFrameworkUtil.getInstance(TPFS_INSTANCE, arguments); TransactionAware txAwareDataset = (TransactionAware) dataset; dsFrameworkUtil.newInMemoryTransactionExecutor(txAwareDataset).execute(new TransactionExecutor.Subroutine() { @Override public void apply() throws Exception { Map<String, String> inputConf = dataset.getInputFormatConfiguration(); String input = inputConf.get(FileInputFormat.INPUT_DIR); Assert.assertNotNull(input); String[] inputs = input.split(","); Assert.assertEquals(1, inputs.length); Assert.assertTrue(inputs[0].endsWith(expectedPath)); } }); }
@Test public void testInvalidPartitionFilter() throws Exception { final PartitionedFileSet pfs = dsFrameworkUtil.getInstance(pfsInstance); dsFrameworkUtil.newTransactionExecutor((TransactionAware) pfs).execute(new TransactionExecutor.Subroutine() { @Override public void apply() throws Exception { // this should succeed without error (but log a warning) Assert.assertEquals(Collections.EMPTY_SET, pfs.getPartitions(PartitionFilter.builder().addValueCondition("me-not-there", 42).build())); } }); }
private void checkProgramStatus(ArtifactId artifactId, ProgramRunId runId, ProgramRunStatus expectedStatus) throws InterruptedException, ExecutionException, TimeoutException { Tasks.waitFor(expectedStatus, () -> txnl.execute(() -> { RunRecordMeta meta = metadataStoreDataset.getRun(runId); if (meta == null) { return null; } Assert.assertEquals(artifactId, meta.getArtifactId()); return meta.getStatus(); }), 10, TimeUnit.SECONDS); }
@After public void cleanupTest() throws Exception { txnl.execute(() -> { Scanner scanner = appMetaTable.scan(null, null); Row row; while ((row = scanner.next()) != null) { appMetaTable.delete(row.getRow()); } }); }