internal NACalibrationLoop(long endTime, NonAtomicInteger obj, CyclicBarrier b) { this.endTime = endTime; this.obj = obj; this.barrier = b; obj.set_Renamed(CASLoops.rng.next()); }
internal VolatileLoop(long iters, VolatileInteger obj, CyclicBarrier b) { this.iters = iters; this.obj = obj; this.barrier = b; obj.set_Renamed(CASLoops.rng.next()); }
internal LockedLoop(long iters, LockedInteger obj, CyclicBarrier b) { this.iters = iters; this.obj = obj; this.barrier = b; obj.set_Renamed(CASLoops.rng.next()); }
internal static void runCalibration(int n, long nms) { long now = (System.DateTime.Now.Ticks - 621355968000000000) / 10000; long endTime = now + nms; CyclicBarrier b = new CyclicBarrier(n + 1); totalIters.Value = (0); NonAtomicInteger a = new NonAtomicInteger(); for (int j = 0; j < n; ++j) { new SupportClass.ThreadClass(new System.Threading.ThreadStart(new NACalibrationLoop(endTime, a, b).Run)).Start(); } b.Await(); b.Await(); long ipt = totalIters.Value / n; if (ipt > loopIters[n]) { loopIters[n] = ipt; } if (sum.Value == 0) { System.Console.Out.Write(" "); } }
public _Callable_210(GCTest _enclosing, CyclicBarrier refUpdateLockedRef, CyclicBarrier packRefsDone) { this._enclosing = _enclosing; this.refUpdateLockedRef = refUpdateLockedRef; this.packRefsDone = packRefsDone; }
public virtual void ConcurrentRepack() { // // leave the syncPoint in broken state so any awaiting // threads and any threads that call await in the future get // the BrokenBarrierException // CyclicBarrier syncPoint = new CyclicBarrier(1); RevBlob a = tr.Blob("a"); tr.LightweightTag("t", a); ExecutorService pool = Executors.NewFixedThreadPool(2); try { _T187790690 repack1 = new _T187790690(this) { syncPoint = syncPoint }; //_T187790690 repack2 = new _T187790690(this) { syncPoint = syncPoint }; Future <int> result1 = pool.Submit(repack1); //Future<int> result2 = pool.Submit(repack2); NUnit.Framework.Assert.AreEqual(0, result1.Get()); // + result2.Get()); } finally { pool.Shutdown(); pool.AwaitTermination(long.MaxValue, TimeUnit.SECONDS); } }
internal NonAtomicLoop(long iters, NonAtomicInteger obj, CyclicBarrier b) { this.iters = iters; this.obj = obj; this.barrier = b; obj.set_Renamed(CASLoops.rng.next()); }
internal AtomicLoop(long iters, AtomicInteger obj, CyclicBarrier b) { this.iters = iters; this.obj = obj; this.barrier = b; obj.Value = (CASLoops.rng.next()); }
public StubbedMergeManager(JobConf conf, ExceptionReporter reporter, CyclicBarrier mergeStart, CyclicBarrier mergeComplete) : base(null, conf, Org.Mockito.Mockito.Mock <LocalFileSystem>(), null, null, null, null, null, null, null, null, reporter, null, Org.Mockito.Mockito.Mock <MapOutputFile >()) { mergeThread.SetSyncBarriers(mergeStart, mergeComplete); }
public _Callable_185(GCTest _enclosing, RevBlob b, CyclicBarrier refUpdateLockedRef , CyclicBarrier packRefsDone) { this._enclosing = _enclosing; this.b = b; this.refUpdateLockedRef = refUpdateLockedRef; this.packRefsDone = packRefsDone; }
public _Thread_616(CyclicBarrier barrier, DataNode dn, string newDirs, IList <Exception > exceptions) { this.barrier = barrier; this.dn = dn; this.newDirs = newDirs; this.exceptions = exceptions; }
/// <summary> /// Test the case that remove a data volume on a particular DataNode when the /// volume is actively being written. /// </summary> /// <param name="dataNodeIdx">the index of the DataNode to remove a volume.</param> /// <exception cref="System.IO.IOException"/> /// <exception cref="Org.Apache.Hadoop.Conf.ReconfigurationException"/> /// <exception cref="Sharpen.TimeoutException"/> /// <exception cref="System.Exception"/> /// <exception cref="Sharpen.BrokenBarrierException"/> private void TestRemoveVolumeBeingWrittenForDatanode(int dataNodeIdx) { // Starts DFS cluster with 3 DataNodes to form a pipeline. StartDFSCluster(1, 3); short Replication = 3; DataNode dn = cluster.GetDataNodes()[dataNodeIdx]; FileSystem fs = cluster.GetFileSystem(); Path testFile = new Path("/test"); long lastTimeDiskErrorCheck = dn.GetLastDiskErrorCheck(); FSDataOutputStream @out = fs.Create(testFile, Replication); Random rb = new Random(0); byte[] writeBuf = new byte[BlockSize / 2]; // half of the block. rb.NextBytes(writeBuf); @out.Write(writeBuf); @out.Hflush(); // Make FsDatasetSpi#finalizeBlock a time-consuming operation. So if the // BlockReceiver releases volume reference before finalizeBlock(), the blocks // on the volume will be removed, and finalizeBlock() throws IOE. FsDatasetSpi <FsVolumeSpi> data = dn.data; dn.data = Org.Mockito.Mockito.Spy(data); Org.Mockito.Mockito.DoAnswer(new _Answer_599(data)).When(dn.data).FinalizeBlock(Matchers.Any <ExtendedBlock>()); // Bypass the argument to FsDatasetImpl#finalizeBlock to verify that // the block is not removed, since the volume reference should not // be released at this point. CyclicBarrier barrier = new CyclicBarrier(2); IList <string> oldDirs = GetDataDirs(dn); string newDirs = oldDirs[1]; // Remove the first volume. IList <Exception> exceptions = new AList <Exception>(); Sharpen.Thread reconfigThread = new _Thread_616(barrier, dn, newDirs, exceptions); reconfigThread.Start(); barrier.Await(); rb.NextBytes(writeBuf); @out.Write(writeBuf); @out.Hflush(); @out.Close(); reconfigThread.Join(); // Verify the file has sufficient replications. DFSTestUtil.WaitReplication(fs, testFile, Replication); // Read the content back byte[] content = DFSTestUtil.ReadFileBuffer(fs, testFile); NUnit.Framework.Assert.AreEqual(BlockSize, content.Length); // If an IOException thrown from BlockReceiver#run, it triggers // DataNode#checkDiskError(). So we can test whether checkDiskError() is called, // to see whether there is IOException in BlockReceiver#run(). NUnit.Framework.Assert.AreEqual(lastTimeDiskErrorCheck, dn.GetLastDiskErrorCheck( )); if (!exceptions.IsEmpty()) { throw new IOException(exceptions[0].InnerException); } }
public virtual void Setup() { localFS = FileContext.GetLocalFSFileContext(); tmpDir.Mkdirs(); logsDir.Mkdirs(); remoteLogsDir.Mkdirs(); nmLocalDir.Mkdirs(); syncBarrier = new CyclicBarrier(2); }
public virtual void SetSyncBarriers(CyclicBarrier mergeStart, CyclicBarrier mergeComplete ) { lock (this) { this.mergeStart = mergeStart; this.mergeComplete = mergeComplete; } }
/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> /// <exception cref="System.IO.IOException"/> protected internal MockNMClientAsync2(TestNMClientAsync _enclosing, CyclicBarrier barrierA, CyclicBarrier barrierB, CyclicBarrier barrierC) : base(typeof(TestNMClientAsync.MockNMClientAsync2).FullName, this._enclosing.MockNMClient (0), new TestNMClientAsync.TestCallbackHandler2(this, barrierC)) { this._enclosing = _enclosing; this.barrierA = barrierA; this.barrierB = barrierB; }
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 _Runnable_915(CyclicBarrier barrier, int num, AtomicBoolean leaderRunning, TestRPC.TestProtocol proxy, AtomicReference <Exception> error, CountDownLatch latch ) { this.barrier = barrier; this.num = num; this.leaderRunning = leaderRunning; this.proxy = proxy; this.error = error; this.latch = latch; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void withConstraint(org.neo4j.function.ThrowingFunction<java.util.concurrent.CyclicBarrier,org.neo4j.graphdb.Node,Exception> action) throws Exception private void WithConstraint(ThrowingFunction <CyclicBarrier, Node, Exception> action) { // given Db.execute("CREATE CONSTRAINT ON (foo:Foo) ASSERT foo.bar IS UNIQUE"); CyclicBarrier barrier = new CyclicBarrier(2); Node node = MergeNode(); // when IList <Node> result = await(Threads.multiple(barrier.Parties, action, barrier)); // then assertEquals("size of result", 2, result.Count); assertEquals(node, result[0]); assertEquals(node, result[1]); }
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(); }
internal static long runLocked(int n, long iters) { LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer(); CyclicBarrier b = new CyclicBarrier(n + 1, timer); LockedInteger a = new LockedInteger(); for (int j = 0; j < n; ++j) { new SupportClass.ThreadClass(new System.Threading.ThreadStart(new LockedLoop(iters, a, b).Run)).Start(); } b.Await(); b.Await(); if (sum.Value == 0) { System.Console.Out.Write(" "); } return(timer.Time); }
public virtual void TestConcurrentFormat() { URI uri = BKJMUtil.CreateJournalURI("/hdfsjournal-concurrentformat"); NamespaceInfo nsi = NewNSInfo(); // populate with data first BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, uri, nsi); bkjm.Format(nsi); for (int i = 1; i < 100 * 2; i += 2) { bkjm.StartLogSegment(i, NameNodeLayoutVersion.CurrentLayoutVersion); bkjm.FinalizeLogSegment(i, i + 1); } bkjm.Close(); int numThreads = 40; IList <Callable <TestBookKeeperJournalManager.ThreadStatus> > threads = new AList <Callable <TestBookKeeperJournalManager.ThreadStatus> >(); CyclicBarrier barrier = new CyclicBarrier(numThreads); for (int i_1 = 0; i_1 < numThreads; i_1++) { threads.AddItem(new _Callable_784(uri, nsi, barrier)); } ExecutorService service = Executors.NewFixedThreadPool(numThreads); IList <Future <TestBookKeeperJournalManager.ThreadStatus> > statuses = service.InvokeAll (threads, 60, TimeUnit.Seconds); int numCompleted = 0; foreach (Future <TestBookKeeperJournalManager.ThreadStatus> s in statuses) { NUnit.Framework.Assert.IsTrue(s.IsDone()); NUnit.Framework.Assert.IsTrue("Thread threw invalid exception", s.Get() == TestBookKeeperJournalManager.ThreadStatus .Completed || s.Get() == TestBookKeeperJournalManager.ThreadStatus.Goodexception ); if (s.Get() == TestBookKeeperJournalManager.ThreadStatus.Completed) { numCompleted++; } } Log.Info("Completed " + numCompleted + " formats"); NUnit.Framework.Assert.IsTrue("No thread managed to complete formatting", numCompleted > 0); }
/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> public virtual void TestRPCInterrupted() { Configuration conf = new Configuration(); Server server = new RPC.Builder(conf).SetProtocol(typeof(TestRPC.TestProtocol)).SetInstance (new TestRPC.TestImpl()).SetBindAddress(Address).SetPort(0).SetNumHandlers(5).SetVerbose (true).SetSecretManager(null).Build(); server.Start(); int numConcurrentRPC = 200; IPEndPoint addr = NetUtils.GetConnectAddress(server); CyclicBarrier barrier = new CyclicBarrier(numConcurrentRPC); CountDownLatch latch = new CountDownLatch(numConcurrentRPC); AtomicBoolean leaderRunning = new AtomicBoolean(true); AtomicReference <Exception> error = new AtomicReference <Exception>(); Thread leaderThread = null; for (int i = 0; i < numConcurrentRPC; i++) { int num = i; TestRPC.TestProtocol proxy = RPC.GetProxy <TestRPC.TestProtocol>(TestRPC.TestProtocol .versionID, addr, conf); Thread rpcThread = new Thread(new _Runnable_915(barrier, num, leaderRunning , proxy, error, latch)); rpcThread.Start(); if (leaderThread == null) { leaderThread = rpcThread; } } // let threads get past the barrier Thread.Sleep(1000); // stop a single thread while (leaderRunning.Get()) { leaderThread.Interrupt(); } latch.Await(); // should not cause any other thread to get an error Assert.True("rpc got exception " + error.Get(), error.Get() == null); server.Stop(); }
public virtual void ConcurrentPackRefs_onlyOneWritesPackedRefs() { RevBlob a = tr.Blob("a"); tr.LightweightTag("t", a); CyclicBarrier syncPoint = new CyclicBarrier(2); Callable <int> packRefs = new _Callable_131(this, syncPoint); ExecutorService pool = Executors.NewFixedThreadPool(2); try { Future <int> p1 = pool.Submit(packRefs); Future <int> p2 = pool.Submit(packRefs); NUnit.Framework.Assert.AreEqual(1, p1.Get() + p2.Get()); } finally { pool.Shutdown(); pool.AwaitTermination(long.MaxValue, TimeUnit.SECONDS); } }
public virtual void TestParallelThreadsWithDifferentLocales() { CyclicBarrier barrier = new CyclicBarrier(2); // wait for the other thread to set its locale ExecutorService pool = Executors.NewFixedThreadPool(2); try { Future <TranslationBundle> root = pool.Submit(new _T879158014(this, NLS.ROOT_LOCALE, barrier)); Future <TranslationBundle> german = pool.Submit(new _T879158014(this, Sharpen.Extensions.GetGermanCulture(), barrier)); NUnit.Framework.Assert.AreEqual(NLS.ROOT_LOCALE, root.Get().EffectiveLocale()); NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.GetGermanCulture(), german.Get ().EffectiveLocale()); } finally { pool.Shutdown(); pool.AwaitTermination(long.MaxValue, TimeUnit.SECONDS); } }
private bool SafeAwait(int mySource, CyclicBarrier barrier) { try { barrier.Await(2, TimeUnit.Seconds); } catch (Exception) { results[mySource] = "Interrupted"; return(false); } catch (BrokenBarrierException) { results[mySource] = "Broken Barrier"; return(false); } catch (TimeoutException) { results[mySource] = "Timed out on barrier"; return(false); } return(true); }
public virtual void PackRefsWhileRefUpdated_refUpdateSucceeds() { RevBlob a = tr.Blob("a"); tr.LightweightTag("t", a); RevBlob b = tr.Blob("b"); CyclicBarrier refUpdateLockedRef = new CyclicBarrier(2); CyclicBarrier packRefsDone = new CyclicBarrier(2); ExecutorService pool = Executors.NewFixedThreadPool(2); try { Future <RefUpdate.Result> result = pool.Submit(new _Callable_185(this, b, refUpdateLockedRef , packRefsDone)); pool.Submit <object>(new _Callable_210(this, refUpdateLockedRef, packRefsDone)); NUnit.Framework.Assert.AreEqual(result.Get(), RefUpdate.Result.FORCED); } finally { pool.ShutdownNow(); pool.AwaitTermination(long.MaxValue, TimeUnit.SECONDS); } NUnit.Framework.Assert.AreEqual(repo.GetRef("refs/tags/t").GetObjectId(), b); }
/// <exception cref="System.Exception"/> public virtual void TestOutOfOrder() { CyclicBarrier barrierA = new CyclicBarrier(2); CyclicBarrier barrierB = new CyclicBarrier(2); CyclicBarrier barrierC = new CyclicBarrier(2); asyncClient = new TestNMClientAsync.MockNMClientAsync2(this, barrierA, barrierB, barrierC); asyncClient.Init(new Configuration()); asyncClient.Start(); Container container = MockContainer(1); ContainerLaunchContext clc = recordFactory.NewRecordInstance <ContainerLaunchContext >(); // start container from another thread Sharpen.Thread t = new _Thread_434(this, container, clc); t.Start(); barrierA.Await(); asyncClient.StopContainerAsync(container.GetId(), container.GetNodeId()); barrierC.Await(); NUnit.Framework.Assert.IsFalse("Starting and stopping should be out of order", (( TestNMClientAsync.TestCallbackHandler2)asyncClient.GetCallbackHandler()).exceptionOccurred .Get()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void concurrentStartupShouldWork() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ConcurrentStartupShouldWork() { // Ensures that the instances don't race to create the test's base directory and only care about their own. TestDirectory.directory("nothingToSeeHereMoveAlong"); int[] clusterPorts = new int[] { PortAuthority.allocatePort(), PortAuthority.allocatePort(), PortAuthority.allocatePort() }; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String initialHosts = initialHosts(clusterPorts); string initialHosts = initialHosts(clusterPorts); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CyclicBarrier barrier = new java.util.concurrent.CyclicBarrier(clusterPorts.length); CyclicBarrier barrier = new CyclicBarrier(clusterPorts.Length); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<Thread> daThreads = new java.util.ArrayList<>(clusterPorts.length); IList <Thread> daThreads = new List <Thread>(clusterPorts.Length); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final HighlyAvailableGraphDatabase[] dbs = new HighlyAvailableGraphDatabase[clusterPorts.length]; HighlyAvailableGraphDatabase[] dbs = new HighlyAvailableGraphDatabase[clusterPorts.Length]; for (int i = 0; i < clusterPorts.Length; i++) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int finalI = i; int finalI = i; Thread t = new Thread(() => { try { barrier.await(); dbs[finalI] = StartDbAtBase(finalI, initialHosts, clusterPorts[finalI]); } catch (Exception e) when(e is InterruptedException || e is BrokenBarrierException) { throw new Exception(e); } }); daThreads.Add(t); t.Start(); } foreach (Thread daThread in daThreads) { daThread.Join(); } bool masterDone = false; foreach (HighlyAvailableGraphDatabase db in dbs) { if (Db.Master) { if (masterDone) { throw new Exception("Two masters discovered"); } masterDone = true; } using (Transaction tx = Db.beginTx()) { Db.createNode(); tx.Success(); } } assertTrue(masterDone); foreach (HighlyAvailableGraphDatabase db in dbs) { Db.shutdown(); } }
public _Callable_784(URI uri, NamespaceInfo nsi, CyclicBarrier barrier) { this.uri = uri; this.nsi = nsi; this.barrier = barrier; }
internal ContainerManagerForTest(CyclicBarrier startLaunchBarrier, CyclicBarrier completeLaunchBarrier) { this.startLaunchBarrier = startLaunchBarrier; this.completeLaunchBarrier = completeLaunchBarrier; }