public _Runnable_194(string[] results, TestMetricsSystemImpl.CollectingSink sink, CyclicBarrier barrier1, TestMetricsSystemImpl.TestSource[] sources, MetricsSystemImpl ms, CyclicBarrier barrier2) { this.results = results; this.sink = sink; this.barrier1 = barrier1; this.sources = sources; this.ms = ms; this.barrier2 = barrier2; }
public virtual void TestMultiThreadedPublish() { int numThreads = 10; new ConfigBuilder().Add("*.period", 80).Add("test.sink.collector." + MetricsConfig .QueueCapacityKey, numThreads).Save(TestMetricsConfig.GetTestFilename("hadoop-metrics2-test" )); MetricsSystemImpl ms = new MetricsSystemImpl("Test"); ms.Start(); TestMetricsSystemImpl.CollectingSink sink = new TestMetricsSystemImpl.CollectingSink (numThreads); ms.RegisterSink("collector", "Collector of values from all threads.", sink); TestMetricsSystemImpl.TestSource[] sources = new TestMetricsSystemImpl.TestSource [numThreads]; Thread[] threads = new Thread[numThreads]; string[] results = new string[numThreads]; CyclicBarrier barrier1 = new CyclicBarrier(numThreads); CyclicBarrier barrier2 = new CyclicBarrier(numThreads); for (int i = 0; i < numThreads; i++) { sources[i] = ms.Register("threadSource" + i, "A source of my threaded goodness.", new TestMetricsSystemImpl.TestSource("threadSourceRec" + i)); threads[i] = new Thread(new _Runnable_194(results, sink, barrier1, sources , ms, barrier2), string.Empty + i); } // Wait for all the threads to come here so we can hammer // the system at the same time // Since some other thread may have snatched my metric, // I need to wait for the threads to finish before checking. foreach (Thread t in threads) { t.Start(); } foreach (Thread t_1 in threads) { t_1.Join(); } Assert.Equal(0L, ms.droppedPubAll.Value()); Assert.True(StringUtils.Join("\n", Arrays.AsList(results)), Iterables .All(Arrays.AsList(results), new _Predicate_240())); ms.Stop(); ms.Shutdown(); }