public static Statistics completionTime() { return sw.durations().statistics(); }
protected static <T> Statistics time(String desc, int repeat, Callable<T> runnable, Consumer<T> cleanup) throws InterruptedException { sw.start(); try { sws.time(repeat, runnable, result -> { if (cleanup != null) cleanup.accept(result); }); } catch (Throwable t) { t.printStackTrace(); fail(t.getMessage()); } sw.stop(); // if (desc != null) Testing.print(60, "Time to " + desc + ":", sw.durations().statistics().getTotalAsString()); // Testing.print(60,"Total clock time:",sw.durations().statistics().getTotalAsString()); // Testing.print(54,"Time to invoke the functions:",sws); return sw.durations().statistics(); }
Testing.print("Waited a total of " + sw.durations().statistics().getTotalAsString() + " for the replica to catch up to the master."); } catch (InterruptedException e) { Thread.interrupted();
@Test @SkipLongRunning public void shouldStartClusterAndAllowProducersAndConsumersToUseIt() throws Exception { Testing.Debug.enable(); final String topicName = "topicA"; final CountDownLatch completion = new CountDownLatch(2); final int numMessages = 100; final AtomicLong messagesRead = new AtomicLong(0); // Start a cluster and create a topic ... cluster.addBrokers(1).startup(); cluster.createTopics(topicName); // Consume messages asynchronously ... Stopwatch sw = Stopwatch.reusable().start(); cluster.useTo().consumeIntegers(topicName, numMessages, 10, TimeUnit.SECONDS, completion::countDown, (key, value) -> { messagesRead.incrementAndGet(); return true; }); // Produce some messages asynchronously ... cluster.useTo().produceIntegers(topicName, numMessages, 1, completion::countDown); // Wait for both to complete ... if (completion.await(10, TimeUnit.SECONDS)) { sw.stop(); Testing.debug("Both consumer and producer completed normally in " + sw.durations()); } else { Testing.debug("Consumer and/or producer did not completed normally"); } assertThat(messagesRead.get()).isEqualTo(numMessages); }
Testing.debug("The consumer completed normally in " + sw.durations()); } else { Testing.debug("Consumer did not completed normally");
Testing.debug("The consumer completed normally in " + sw.durations()); } else { Testing.debug("Consumer did not completed normally");
Testing.print("Waited a total of " + sw.durations().statistics().getTotalAsString() + " for the replica to catch up to the master."); } catch (InterruptedException e) { Thread.interrupted();