private void waitForSegmentPublishAndHandoff(long timeout) throws InterruptedException, ExecutionException, TimeoutException { if (!pendingHandoffs.isEmpty()) { ListenableFuture<?> allHandoffs = Futures.allAsList(pendingHandoffs); log.info("Waiting for handoffs"); if (timeout > 0) { allHandoffs.get(timeout, TimeUnit.MILLISECONDS); } else { allHandoffs.get(); } } }
private void verifyAndMergeCheckpoints(final Collection<TaskGroup> taskGroupsToVerify) { final List<ListenableFuture<?>> futures = new ArrayList<>(); for (TaskGroup taskGroup : taskGroupsToVerify) { futures.add(workerExec.submit(() -> verifyAndMergeCheckpoints(taskGroup))); } try { Futures.allAsList(futures).get(futureTimeoutInSeconds, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { throw new RuntimeException(e); } }
@Override public List<String> call() throws InterruptedException, ExecutionException, TimeoutException { RangeResponse response = kvStub.range(request).get(config.getOperationTimeoutMilliseconds(), TimeUnit.MILLISECONDS); List<String> result = new ArrayList<>(); for (KeyValue each : response.getKvsList()) { String childFullPath = each.getKey().toStringUtf8(); result.add(childFullPath.substring(childFullPath.lastIndexOf("/") + 1)); } return result; } });
@Test(timeout = 90_000L) public void testConcurrentQueries() throws Exception { final List<ListenableFuture<Integer>> futures = new ArrayList<>(); final ListeningExecutorService exec = MoreExecutors.listeningDecorator( Executors.newFixedThreadPool(AVATICA_CONFIG.getMaxStatementsPerConnection()) ); for (int i = 0; i < 2000; i++) { final String query = StringUtils.format("SELECT COUNT(*) + %s AS ci FROM foo", i); futures.add( exec.submit(() -> { try ( final Statement statement = client.createStatement(); final ResultSet resultSet = statement.executeQuery(query) ) { final List<Map<String, Object>> rows = getRows(resultSet); return ((Number) Iterables.getOnlyElement(rows).get("ci")).intValue(); } catch (SQLException e) { throw Throwables.propagate(e); } }) ); } final List<Integer> integers = Futures.allAsList(futures).get(); for (int i = 0; i < 2000; i++) { Assert.assertEquals(i + 6, (int) integers.get(i)); } }
@Test public void testSupervisorTaskDefaultSingleTestTaskHappyCase() throws Exception { // testTask should never timeout TestTask testTask = new TestTask(1, false); TimedSupervisorTask supervisorTask = new TimedSupervisorTask("test", scheduler, executor, 5, TimeUnit.SECONDS, EXP_BACK_OFF_BOUND, testTask); helperExecutor.submit(supervisorTask).get(); Assert.assertEquals(1, maxConcurrentTestTasks.get()); Assert.assertEquals(0, testTaskCounter.get()); Assert.assertEquals(1, testTaskStartCounter.get()); Assert.assertEquals(1, testTaskSuccessfulCounter.get()); Assert.assertEquals(0, testTaskInterruptedCounter.get()); }
@Test(enabled = false) public void testOutOfCapacityResponse() throws Exception { PropertiesConfiguration conf = new PropertiesConfiguration(); conf.setProperty(ResourceLimitPolicy.TABLE_THREADS_HARD_LIMIT, 5); conf.setProperty(MultiLevelPriorityQueue.MAX_PENDING_PER_GROUP_KEY, 1); TestPriorityScheduler scheduler = TestPriorityScheduler.create(conf); scheduler.start(); List<ListenableFuture<byte[]>> results = new ArrayList<>(); results.add(scheduler.submit(createServerQueryRequest("1", metrics))); TestSchedulerGroup group = TestPriorityScheduler.groupFactory.groupMap.get("1"); group.addReservedThreads(10); group.addLast(createQueryRequest("1", metrics)); results.add(scheduler.submit(createServerQueryRequest("1", metrics))); DataTable dataTable = DataTableFactory.getDataTable(results.get(1).get()); assertTrue(dataTable.getMetadata() .containsKey(DataTable.EXCEPTION_METADATA_KEY + QueryException.SERVER_OUT_OF_CAPACITY_ERROR.getErrorCode())); scheduler.stop(); }
@Test public void mine1() throws Exception { blockchain.setMinerCoinbase(Hex.decode("ee0250c19ad59305b2bdb61f34b45b72fe37154f")); Block parent = blockchain.getBestBlock(); List<Transaction> pendingTx = new ArrayList<>(); ECKey senderKey = ECKey.fromPrivate(Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c")); byte[] receiverAddr = Hex.decode("31e2e1ed11951c7091dfba62cd4b7145e947219c"); Transaction tx = new Transaction(new byte[] {0}, new byte[] {1}, ByteUtil.longToBytesNoLeadZeroes(0xfffff), receiverAddr, new byte[] {77}, new byte[0]); tx.sign(senderKey); pendingTx.add(tx); Block b = blockchain.createNewBlock(parent, pendingTx, Collections.EMPTY_LIST); System.out.println("Mining..."); Ethash.getForBlock(SystemProperties.getDefault(), b.getNumber()).mineLight(b).get(); System.out.println("Validating..."); boolean valid = Ethash.getForBlock(SystemProperties.getDefault(), b.getNumber()).validate(b.getHeader()); Assert.assertTrue(valid); System.out.println("Connecting..."); ImportResult importResult = blockchain.tryToConnect(b); Assert.assertTrue(importResult == ImportResult.IMPORTED_BEST); System.out.println(Hex.toHexString(blockchain.getRepository().getRoot())); } }
@Test(timeOut = SHUTDOWN_TIMEOUT_MILLIS) public void testShutdown() throws Exception List<ListenableFuture<?>> queryFutures = new ArrayList<>(); for (int i = 0; i < 5; i++) { queryFutures.add(executor.submit(() -> queryRunner.execute("SELECT COUNT(*), clerk FROM orders GROUP BY clerk"))); Futures.allAsList(queryFutures).get();
private JobId createAndAwaitJobRunning() throws Exception { final CreateJobResponse jobby = client.createJob(job).get(); assertEquals(CreateJobResponse.Status.OK, jobby.getStatus()); final JobId jobId = job.getId(); final JobDeployResponse deployResponse = client.deploy( Deployment.of(jobId, START), TEST_HOST).get(); assertEquals(JobDeployResponse.Status.OK, deployResponse.getStatus()); awaitJobState(client, TEST_HOST, jobId, State.RUNNING, 30, TimeUnit.SECONDS); return jobId; }
@Test(timeOut = 10_000) public void testGetPartial() throws Exception { AsyncQueue<String> queue = new AsyncQueue<>(4, executor); queue.offer("1"); queue.offer("2"); queue.offer("3"); assertEquals(queue.getBatchAsync(100).get(), ImmutableList.of("1", "2", "3")); queue.finish(); assertTrue(queue.isFinished()); }
@BenchmarkOptions(warmupRounds = 100, benchmarkRounds = 100, clock = Clock.REAL_TIME, callgc = true) @Ignore @Test futures.add( executorService.submit( new Runnable() Futures.allAsList(futures).get(); Assert.assertTrue(StringUtils.format("Index too small %d, expected %d across %d loops", index.get(), totalIndexSize, loops), index.get() >= totalIndexSize); for (int i = 0; i < index.get(); ++i) { Assert.assertEquals(i, concurrentIndexible.get(i).intValue());
@Test public void testRemoveJobWithoutHistory() throws Exception { final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND); final JobDeleteResponse response = defaultClient().deleteJob(jobId).get(WAIT_TIMEOUT_SECONDS, SECONDS); assertEquals(JobDeleteResponse.Status.OK, response.getStatus()); }
@Test public void testStartStopQueries() throws ExecutionException, InterruptedException, IOException { TestPriorityScheduler scheduler = TestPriorityScheduler.create(); scheduler.start(); PropertiesConfiguration conf = new PropertiesConfiguration(); conf.setProperty(ResourceLimitPolicy.TABLE_THREADS_HARD_LIMIT, 5); conf.setProperty(MultiLevelPriorityQueue.MAX_PENDING_PER_GROUP_KEY, 5); List<ListenableFuture<byte[]>> results = new ArrayList<>(); results.add(scheduler.submit(createServerQueryRequest("1", metrics))); TestSchedulerGroup group = TestPriorityScheduler.groupFactory.groupMap.get("1"); group.addReservedThreads(10); group.addLast(createQueryRequest("1", metrics)); results.add(scheduler.submit(createServerQueryRequest("1", metrics))); scheduler.stop(); long queueWakeTimeMicros = ((MultiLevelPriorityQueue) scheduler.getQueue()).getWakeupTimeMicros(); long sleepTimeMs = queueWakeTimeMicros >= 1000 ? queueWakeTimeMicros / 1000 + 10 : 10; Thread.sleep(sleepTimeMs); int hasServerShuttingDownError = 0; for (ListenableFuture<byte[]> result : results) { DataTable table = DataTableFactory.getDataTable(result.get()); hasServerShuttingDownError += table.getMetadata() .containsKey(DataTable.EXCEPTION_METADATA_KEY + QueryException.SERVER_SCHEDULER_DOWN_ERROR.getErrorCode()) ? 1 : 0; } assertTrue(hasServerShuttingDownError > 0); }
@Test public void testHostListJson() throws Exception { final String jsonOutput = cli("hosts", "-f", "--json"); final Map<String, HostStatus> statuses = Json.readUnchecked(jsonOutput, new TypeReference<Map<String, HostStatus>>() {}); final HeliosClient client = defaultClient(); final Map<String, HostStatus> expectedStatuses = client.hostStatuses(ImmutableList.of(hostname1, hostname2)).get(); assertThat(expectedStatuses, equalTo(statuses)); }
@Before public void setup() throws Exception { backupDir = Files.createTempDirectory("helios-zk-updating-persistent-dir-test-backup-"); startDefaultMaster(); client = defaultClient(); final CreateJobResponse created = client.createJob(fooJob).get(); assertEquals(CreateJobResponse.Status.OK, created.getStatus()); }
@Test public void testTernaryOperatorsDecimalDouble() throws Exception { for (BigDecimal first : decimalLefts) { for (Double second : doubleMiddle) { for (BigDecimal third : decimalRights) { assertExecute(generateExpression("%s between %s and %s", first, second, third), BOOLEAN, first == null || second == null || third == null ? null : second <= first.doubleValue() && first.compareTo(third) <= 0); } } } Futures.allAsList(futures).get(); }