@Override protected void sleepMicrosUninterruptibly(long micros) { if (micros > 0) { Uninterruptibles.sleepUninterruptibly(micros, MICROSECONDS); } } };
@Override public void sleep(long ms) { Uninterruptibles.sleepUninterruptibly(ms, MILLISECONDS); } };
@Override protected void sleepMicrosUninterruptibly(long micros) { if (micros > 0) { Uninterruptibles.sleepUninterruptibly(micros, MICROSECONDS); } } };
@Override protected void sleepMicrosUninterruptibly(long micros) { if (micros > 0) { Uninterruptibles.sleepUninterruptibly(micros, MICROSECONDS); } } };
private static void assertUntilTimeout(Runnable assertion, Duration timeout) { long start = System.nanoTime(); while (!currentThread().isInterrupted()) { try { assertion.run(); return; } catch (AssertionError e) { if (nanosSince(start).compareTo(timeout) > 0) { throw e; } } sleepUninterruptibly(50, MILLISECONDS); } }
private <T> T waitUntilStable(Supplier<T> computation, Duration timeout) { T lastValue = computation.get(); long start = System.nanoTime(); while (!currentThread().isInterrupted() && nanosSince(start).compareTo(timeout) < 0) { sleepUninterruptibly(100, MILLISECONDS); T currentValue = computation.get(); if (currentValue.equals(lastValue)) { return currentValue; } lastValue = currentValue; } throw new UncheckedTimeoutException(); }
public static void assertContainsEventually(Supplier<QueryResult> all, QueryResult expectedSubset, Duration timeout) { long start = System.nanoTime(); while (!Thread.currentThread().isInterrupted()) { try { assertContains(all.get(), expectedSubset); return; } catch (AssertionError e) { if (nanosSince(start).compareTo(timeout) > 0) { throw e; } } sleepUninterruptibly(50, MILLISECONDS); } }
public static void assertContainsEventually(Supplier<MaterializedResult> all, MaterializedResult expectedSubset, Duration timeout) { long start = System.nanoTime(); while (!Thread.currentThread().isInterrupted()) { try { assertContains(all.get(), expectedSubset); return; } catch (AssertionError e) { if (nanosSince(start).compareTo(timeout) > 0) { throw e; } } sleepUninterruptibly(50, MILLISECONDS); } }
@Override public void run() { Uninterruptibles.sleepUninterruptibly(delay, TimeUnit.MILLISECONDS); notifyStarted(); } }.start();
@Override public void run() { Uninterruptibles.sleepUninterruptibly(delay, TimeUnit.MILLISECONDS); notifyStopped(); } }.start();
@Override protected void doStart() { super.doStart(); // This will delay service listener execution at least 150 milliseconds Uninterruptibles.sleepUninterruptibly(150, TimeUnit.MILLISECONDS); } };
void handleConsumerException(Exception e) { // By default, just log the exception and switch back to CONNECTING_TO_BOOTSTRAP_NODE (which will take care of // closing the connection if it exists) LOGGER.warn("Caught Kafka consumer exception while in state {}, disconnecting and trying again for topic {}", _currentState.getStateValue(), _topic, e); Uninterruptibles.sleepUninterruptibly(250, TimeUnit.MILLISECONDS); setCurrentState(new ConnectingToBootstrapNode()); }
@Override protected RawMessage produceRawMessage(MessageInput input) { final byte[] payload; try { final FakeHttpRawMessageGenerator.GeneratorState state = generator.generateState(); payload = objectMapper.writeValueAsBytes(state); final RawMessage raw = new RawMessage(payload); sleepUninterruptibly(rateDeviation(sleepMs, maxSleepDeviation, rand), MILLISECONDS); return raw; } catch (JsonProcessingException e) { log.error("Unable to serialize generator state", e); } return null; }
protected static void assertQueryFailsEventually(QueryRunner queryRunner, Session session, @Language("SQL") String sql, @Language("RegExp") String expectedMessageRegExp, Duration timeout) { long start = System.nanoTime(); while (!Thread.currentThread().isInterrupted()) { try { assertQueryFails(queryRunner, session, sql, expectedMessageRegExp); return; } catch (AssertionError e) { if (nanosSince(start).compareTo(timeout) > 0) { throw e; } } sleepUninterruptibly(50, MILLISECONDS); } }
private static void sleepSuccessfully(long sleepMillis) { Completion completed = new Completion(sleepMillis - SLEEP_SLACK); Uninterruptibles.sleepUninterruptibly(sleepMillis, MILLISECONDS); completed.assertCompletionExpected(); }
public static void waitForServerStarted(NettyTCPServer server, long timeOutInMillis) throws TimeoutException { long endTime = System.currentTimeMillis() + timeOutInMillis; while (System.currentTimeMillis() < endTime) { if (server.isStarted()) { return; } Uninterruptibles.sleepUninterruptibly(10L, TimeUnit.MILLISECONDS); } throw new TimeoutException("Failed to start server in " + timeOutInMillis + "ms"); }
@Override public void run() { for (int j = 0; j < queriesPerThread; j++) { results.add(scheduler.submit(createServerQueryRequest(Integer.toString(index), metrics))); Uninterruptibles.sleepUninterruptibly(random.nextInt(100), TimeUnit.MILLISECONDS); } } }).start();
private BufferedReader getReaderForContainerPort80(GenericContainer container) { return Unreliables.retryUntilSuccess(10, TimeUnit.SECONDS, () -> { Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); Socket socket = new Socket(container.getContainerIpAddress(), container.getFirstMappedPort()); return new BufferedReader(new InputStreamReader(socket.getInputStream())); }); }
@Test public void testCancelOutstandingRequest() throws Exception { Assert.assertTrue(_nettyTCPClientConnection.connect()); ResponseFuture responseFuture = _nettyTCPClientConnection .sendRequest(Unpooled.wrappedBuffer(NettyTestUtils.DUMMY_REQUEST.getBytes()), 1L, 5000L); responseFuture.cancel(false); // Wait for cancel taking effect Uninterruptibles.sleepUninterruptibly(1L, TimeUnit.SECONDS); Assert.assertNull(responseFuture.getOne()); Assert.assertTrue(responseFuture.isCancelled()); }
@Test(invocationCount = 1_000, timeOut = 10_000) public void testConcurrentClose() { List<Type> types = ImmutableList.of(VARCHAR, BIGINT, BIGINT); OperatorContext operatorContext = driverContext.addOperatorContext(0, new PlanNodeId("test"), "values"); ValuesOperator source = new ValuesOperator(operatorContext, rowPagesBuilder(types) .addSequencePage(10, 20, 30, 40) .build()); Operator sink = createSinkOperator(types); Driver driver = Driver.createDriver(driverContext, source, sink); // let these threads race scheduledExecutor.submit(() -> driver.processFor(new Duration(1, TimeUnit.NANOSECONDS))); // don't want to call isFinishedInternal in processFor scheduledExecutor.submit(() -> driver.close()); while (!driverContext.isDone()) { Uninterruptibles.sleepUninterruptibly(1, TimeUnit.MILLISECONDS); } }