@Override public void await(long timeout, TimeUnit unit) throws InterruptedException { latch.await(timeout, unit); }
/** * Create a new variable latch. * * @param initialValue the initial number of latches * @return the variable latch; never null */ public static VariableLatch create(int initialValue) { return new VariableLatch(0); }
@Override public void accept(ChangeEvent event) { final SourceRecord record = event.getRecord(); if ( ignoreTopic(record.topic()) ) { return; } if (latch.getCount() == 0) { if (ignoreExtraRecords) { records.add(record); } else { fail("received more events than expected"); } } else { records.add(record); latch.countDown(); } }
/** * Create a new variable latch. * * @return the variable latch; never null */ public static VariableLatch create() { return create(0); }
@Override public void accept(ChangeEvent event) { final SourceRecord record = event.getRecord(); if ( ignoreTopic(record.topic()) ) { return; } if (latch.getCount() == 0) { if (ignoreExtraRecords) { records.add(record); } else { fail("received more events than expected"); } } else { records.add(record); latch.countDown(); } }
/** * Create a new variable latch. * * @return the variable latch; never null */ public static VariableLatch create() { return create(0); }
@Override public void await() throws InterruptedException { latch.await(); }
VariableLatch latch = new VariableLatch(0); return new StopwatchSet() { @Override
/** * Wait for the connector to complete processing. If the processor is not running, this method returns immediately; however, * if the processor is {@link #stop() stopped} and restarted before this method is called, this method will return only * when it completes the second time. * * @param timeout the maximum amount of time to wait before returning * @param unit the unit of time; may not be null * @return {@code true} if the connector completed within the timeout (or was not running), or {@code false} if it is still * running when the timeout occurred * @throws InterruptedException if this thread is interrupted while waiting for the completion of the connector */ public boolean await(long timeout, TimeUnit unit) throws InterruptedException { return latch.await(timeout, unit); }
protected TestConsumer(int expectedRecordsCount, String... topicPrefixes) { this.latch = new VariableLatch(expectedRecordsCount); this.records = new ConcurrentLinkedQueue<>(); this.topicPrefixes = Arrays.stream(topicPrefixes) .map(p -> TestHelper.TEST_SERVER + "." + p) .collect(Collectors.toList()); }
/** * Stop the execution of this embedded connector. This method does not block until the connector is stopped; use * {@link #await(long, TimeUnit)} for this purpose. * * @return {@code true} if the connector was {@link #run() running} and will eventually stop, or {@code false} if it was not * running when this method is called * @see #await(long, TimeUnit) */ public boolean stop() { logger.debug("Stopping the embedded engine"); // Signal that the run() method should stop ... Thread thread = this.runningThread.getAndSet(null); if (thread != null) { try { latch.await(Long.valueOf(System.getProperty(WAIT_FOR_COMPLETION_BEFORE_INTERRUPT_PROP, Long.toString(WAIT_FOR_COMPLETION_BEFORE_INTERRUPT_DEFAULT.toMillis()))), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { } logger.debug("Interruping the embedded engine's thread " + thread + " (already interrupted: " + thread.isInterrupted() + ")"); // Interrupt the thread in case it is blocked while polling the task for records ... thread.interrupt(); return true; } return false; }
/** * Create a new variable latch. * * @param initialValue the initial number of latches * @return the variable latch; never null */ public static VariableLatch create(int initialValue) { return new VariableLatch(0); }
@Override public void await() throws InterruptedException { latch.await(); }
VariableLatch latch = new VariableLatch(0); return new StopwatchSet() { @Override
@Override public void await(long timeout, TimeUnit unit) throws InterruptedException { latch.await(timeout, unit); }