/** * Test that listening to events for a given map can handle 50 updates per second of 2 MB string * values and are triggering events which contain both the key and value (topic). */ @Test public void testSubscriptionMapEventOnTopicPerformance() { _testMap.clear(); String key = TestUtils.getKey(_mapName, 0); // Create subscriber and register TestChronicleTopicSubscriber topicSubscriber = new TestChronicleTopicSubscriber(key, _twoMbTestStringLength); clientAssetTree.registerTopicSubscriber(_mapName, String.class, String.class, topicSubscriber); Jvm.pause(100); KVSSubscription subscription = (KVSSubscription) serverAssetTree.getAsset(_mapName).subscription(false); Assert.assertEquals(1, subscription.topicSubscriberCount()); // Perform test a number of times to allow the JVM to warm up, but verify runtime against // average TestUtils.runMultipleTimesAndVerifyAvgRuntime( i -> { System.out.println("test"); int events = _noOfPuts * i; waitFor(() -> events == topicSubscriber.getNoOfEvents().get()); Assert.assertEquals(events, topicSubscriber.getNoOfEvents().get()); }, () -> { IntStream.range(0, _noOfPuts) .forEach( i -> { _testMap.put(key, _twoMbTestString); }); }, _noOfRunsToAverage, 3 * _secondInNanos); // Test that the correct number of events was triggered on event listener int events = _noOfPuts * _noOfRunsToAverage; waitFor(() -> events == topicSubscriber.getNoOfEvents().get()); Assert.assertEquals(events, topicSubscriber.getNoOfEvents().get()); clientAssetTree.unregisterTopicSubscriber(_mapName, topicSubscriber); waitFor(() -> 0 == subscription.topicSubscriberCount()); Assert.assertEquals(0, subscription.topicSubscriberCount()); }