//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: public void generateEvent(final org.neo4j.graphdb.event.ErrorState error, final Throwable cause) public virtual void GenerateEvent(ErrorState error, Exception cause) { ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(() => _kernelEventHandlers.kernelPanic(error, cause)); executor.shutdown(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void mergeScanUpdates() throws InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException private void MergeScanUpdates() { ExecutorService executorService = Executors.newFixedThreadPool(_allScanUpdates.Count); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.List<java.util.concurrent.Future<?>> mergeFutures = new java.util.ArrayList<>(); IList <Future <object> > mergeFutures = new List <Future <object> >(); foreach (ThreadLocalBlockStorage part in _allScanUpdates) { BlockStorage <KEY, VALUE> scanUpdates = part.BlockStorage; // Call doneAdding here so that the buffer it allocates if it needs to flush something will be shared with other indexes scanUpdates.DoneAdding(); mergeFutures.Add(executorService.submit(() => { scanUpdates.Merge(_mergeFactor, _cancellation); return(null); })); } executorService.shutdown(); while (!executorService.awaitTermination(1, TimeUnit.SECONDS)) { // just wait longer } // Let potential exceptions in the merge threads have a chance to propagate //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: for (java.util.concurrent.Future<?> mergeFuture : mergeFutures) foreach (Future <object> mergeFuture in mergeFutures) { mergeFuture.get(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPerform500ConcurrentRequests() throws InterruptedException, java.util.concurrent.ExecutionException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void shouldPerform500ConcurrentRequests() { PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.apache.http.impl.client.CloseableHttpClient httpClient = org.apache.http.impl.client.HttpClients.custom().setConnectionManager(cm).build(); CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).build(); Callable <string> performRequest = new CallableAnonymousInnerClass(this, httpClient); int requestsCount = 500; ExecutorService service = Executors.newFixedThreadPool(requestsCount); IList <Callable <string> > requests = new List <Callable <string> >(); for (int i = 0; i < requestsCount; i++) { requests.Add(performRequest); } IList <Future <string> > futures = service.invokeAll(requests); service.shutdown(); service.awaitTermination(1, TimeUnit.HOURS); foreach (Future <string> future in futures) { assertEquals(future.get(), "[]"); } }
// Tests that a listener is only invoked by a single thread at any time even if multiple threads are // invoking the wrapper concurrently. //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void concurrentExecution() throws InterruptedException public virtual void concurrentExecution() { int nThreads = Runtime.Runtime.availableProcessors(); int resultsPerThread = 10; ConcurrentLinkedQueue <string> errors = new ConcurrentLinkedQueue <string>(); System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1); int expectedResultCount = nThreads * resultsPerThread; Listener listener = new Listener(errors, latch); System.Action <CalculationResults> wrapper = new ListenerWrapper(listener, expectedResultCount, ImmutableList.of(), ImmutableList.of()); ExecutorService executor = Executors.newFixedThreadPool(nThreads); CalculationResult result = CalculationResult.of(0, 0, Result.failure(FailureReason.ERROR, "foo")); CalculationTarget target = new CalculationTargetAnonymousInnerClass(this); CalculationResults results = CalculationResults.of(target, ImmutableList.of(result)); IntStream.range(0, expectedResultCount).forEach(i => executor.submit(() => wrapper(results))); latch.await(); executor.shutdown(); if (!errors.Empty) { //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: string allErrors = errors.collect(joining("\n")); fail(allErrors); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("Duplicates") @Test public void stressCache() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void StressCache() { StringFactory factory = new StringFactory(); TemporalIndexCache <string> cache = new TemporalIndexCache <string>(factory); ExecutorService pool = Executors.newFixedThreadPool(20); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.concurrent.Future<?>[] futures = new java.util.concurrent.Future[100]; Future <object>[] futures = new Future[100]; AtomicBoolean shouldContinue = new AtomicBoolean(true); try { for (int i = 0; i < futures.Length; i++) { futures[i] = pool.submit(new CacheStresser(cache, shouldContinue)); } Thread.Sleep(5_000); shouldContinue.set(false); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: for (java.util.concurrent.Future<?> future : futures) foreach (Future <object> future in futures) { future.get(10, TimeUnit.SECONDS); } } finally { pool.shutdown(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldHandleStress() throws java.util.concurrent.ExecutionException, InterruptedException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldHandleStress() { // given int n = 1000; TestStateMachine stateMachine = new TestStateMachine(); ExecutorService executor = Executors.newFixedThreadPool(3); // when //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.concurrent.Future<?> collect = executor.submit(stress(n, () -> collect(stateMachine))); Future <object> collect = executor.submit(Stress(n, () => collect(stateMachine))); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.concurrent.Future<?> stop = executor.submit(stress(n, () -> stateMachine.stop(Long.MAX_VALUE))); Future <object> stop = executor.submit(Stress(n, () => stateMachine.Stop(long.MaxValue))); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.concurrent.Future<?> clear = executor.submit(stress(n, stateMachine::clear)); Future <object> clear = executor.submit(Stress(n, stateMachine.clear)); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.concurrent.Future<?> status = executor.submit(stress(n, stateMachine::status)); Future <object> status = executor.submit(Stress(n, stateMachine.status)); // then without illegal transitions or exceptions collect.get(); stop.get(); clear.get(); status.get(); executor.shutdown(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldMaintainConsistency() throws InterruptedException, java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldMaintainConsistency() { ExecutorService service = SetupWorkload(N); for (int t = 0; t < TimeoutInSeconds; t++) { Thread.Sleep(_oneSecond); if (Errors.Count > ErrorLimit) { break; } } _keepRunning = false; service.shutdown(); service.awaitTermination(5, SECONDS); // Assert that no errors occured string msg = string.join(Environment.NewLine, Errors.Select(Exception.getMessage).ToList()); assertThat(msg, Errors, empty()); // Assert that user and role repos are consistent ListSnapshot <User> users = _userRepository.PersistedSnapshot; ListSnapshot <RoleRecord> roles = _roleRepository.PersistedSnapshot; assertTrue("User and role repositories are no longer consistent", RoleRepository.validate(users.Values(), roles.Values())); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @After public void cleanup() public virtual void Cleanup() { if (_executorService != null && !_executorService.Terminated) { _executorService.shutdown(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSupportConcurrentConsumptionOfSlaves() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldSupportConcurrentConsumptionOfSlaves() { // Given LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); HighAvailabilitySlaves haSlaves = new HighAvailabilitySlaves(ClusterMembersOfSize(1000), mock(typeof(Cluster)), new DefaultSlaveFactory(NullLogProvider.Instance, new Monitors(), 42, Suppliers.singleton(logEntryReader)), new HostnamePort(null, 0)); // When ExecutorService executor = Executors.newFixedThreadPool(5); for (int i = 0; i < 5; i++) { executor.submit(SlavesConsumingRunnable(haSlaves)); } executor.shutdown(); executor.awaitTermination(30, SECONDS); // Then int slavesCount = 0; LifeSupport life = ReflectionUtil.getPrivateField(haSlaves, "life", typeof(LifeSupport)); foreach (Lifecycle lifecycle in life.LifecycleInstances) { if (lifecycle is Slave) { slavesCount++; } } assertEquals("Unexpected number of slaves", 1000 - 1, slavesCount); // One instance is master }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void readAndWrite(int nReaders, int time, java.util.concurrent.TimeUnit unit) throws Throwable private void ReadAndWrite(int nReaders, int time, TimeUnit unit) { using (DefaultFileSystemAbstraction fsa = new DefaultFileSystemAbstraction()) { LifeSupport lifeSupport = new LifeSupport(); T raftLog = CreateRaftLog(fsa, Dir.directory()); lifeSupport.Add(raftLog); lifeSupport.Start(); try { ExecutorService es = Executors.newCachedThreadPool(); ICollection <Future <long> > futures = new List <Future <long> >(); futures.Add(es.submit(new TimedTask(this, () => write(raftLog), time, unit))); for (int i = 0; i < nReaders; i++) { futures.Add(es.submit(new TimedTask(this, () => read(raftLog), time, unit))); } foreach (Future <long> f in futures) { long iterations = f.get(); } es.shutdown(); } finally { lifeSupport.Shutdown(); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void populatorMarkedAsFailed() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void PopulatorMarkedAsFailed() { SetProperty(BATCH_SIZE_NAME, 2); EntityUpdates update1 = NodeUpdates(1, PROPERTY_ID, "aaa", LABEL_ID); EntityUpdates update2 = NodeUpdates(1, PROPERTY_ID, "bbb", LABEL_ID); IndexStoreView storeView = NewStoreView(update1, update2); Exception batchFlushError = new Exception("Batch failed"); IndexPopulator populator; ExecutorService executor = Executors.newSingleThreadExecutor(); try { BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, executor, NullLogProvider.Instance, mock(typeof(SchemaState))); populator = AddPopulator(batchingPopulator, _index1); IList <IndexEntryUpdate <IndexDescriptor> > expected = ForUpdates(_index1, update1, update2); doThrow(batchFlushError).when(populator).add(expected); batchingPopulator.IndexAllEntities().run(); } finally { executor.shutdown(); executor.awaitTermination(1, TimeUnit.MINUTES); } verify(populator).markAsFailed(failure(batchFlushError).asString()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void someData() throws InterruptedException private void SomeData() { int threads = Runtime.Runtime.availableProcessors(); ExecutorService executor = Executors.newFixedThreadPool(threads); for (int i = 0; i < threads; i++) { executor.submit(() => { for (int t = 0; t < 100; t++) { using (Transaction tx = Db.beginTx()) { for (int n = 0; n < 100; n++) { Node node = Db.createNode(_labels); foreach (string key in _keys) { node.setProperty(key, format("some value %d", n)); } } tx.success(); } } }); } executor.shutdown(); while (!executor.awaitTermination(1, SECONDS)) { // Just wait longer } }
public virtual void ShouldBeAbleToReadPropertiesFromNewNodeReturnedFromIndex() { string propertyKey = System.Guid.randomUUID().ToString(); string propertyValue = System.Guid.randomUUID().ToString(); AtomicBoolean start = new AtomicBoolean(false); int readerDelay = ThreadLocalRandom.current().Next(MAX_READER_DELAY_MS); Writer writer = new Writer(Db, propertyKey, propertyValue, start); Reader reader = new Reader(Db, propertyKey, propertyValue, start, readerDelay); ExecutorService executor = Executors.newFixedThreadPool(2); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.concurrent.Future<?> readResult; Future <object> readResult; //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.concurrent.Future<?> writeResult; Future <object> writeResult; try { writeResult = executor.submit(writer); readResult = executor.submit(reader); start.set(true); } finally { executor.shutdown(); executor.awaitTermination(20, TimeUnit.SECONDS); } assertNull(writeResult.get()); assertNull(readResult.get()); }
public override void Stop() { _boltSchedulers.Values.forEach(this.stopScheduler); _boltSchedulers.Clear(); _forkJoinThreadPool.shutdown(); _forkJoinThreadPool = null; }
public static Future <T> Future <T>(Callable <T> task) { ExecutorService executor = Executors.newSingleThreadExecutor(); Future <T> future = executor.submit(task); executor.shutdown(); return(future); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void concurrentlyPublishedEventsMustAllBeProcessed() internal virtual void ConcurrentlyPublishedEventsMustAllBeProcessed() { assertTimeout(ofSeconds(10), () => { EventConsumer consumer = new EventConsumer(); System.Threading.CountdownEvent startLatch = new System.Threading.CountdownEvent(1); const int threads = 10; const int iterations = 2_000; AsyncEvents <Event> asyncEvents = new AsyncEvents <Event>(consumer, AsyncEvents.Monitor_Fields.None); _executor.submit(asyncEvents); ExecutorService threadPool = Executors.newFixedThreadPool(threads); ThreadStart runner = () => { try { startLatch.await(); } catch (InterruptedException e) { throw new Exception(e); } for (int i = 0; i < iterations; i++) { asyncEvents.Send(new Event()); } }; for (int i = 0; i < threads; i++) { threadPool.submit(runner); } startLatch.countDown(); Thread thisThread = Thread.CurrentThread; int eventCount = threads * iterations; try { for (int i = 0; i < eventCount; i++) { Event @event = consumer.Poll(1, TimeUnit.SECONDS); if (@event == null) { i--; } else { assertThat(@event.ProcessedBy, @is(not(thisThread))); } } } finally { asyncEvents.Shutdown(); threadPool.shutdown(); } }); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFailDifferentlyIfTooManyFailedAuthAttempts() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldFailDifferentlyIfTooManyFailedAuthAttempts() { // Given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final long timeout = System.currentTimeMillis() + 60_000; long timeout = DateTimeHelper.CurrentUnixTimeMillis() + 60_000; FailureMessage failureMessage = null; // When while (failureMessage == null) { if (DateTimeHelper.CurrentUnixTimeMillis() > timeout) { fail("Timed out waiting for the authentication failure to occur."); } ExecutorService executor = Executors.newFixedThreadPool(10); // Fire up some parallel connections that all send wrong authentication tokens IList <CompletableFuture <FailureMessage> > futures = new List <CompletableFuture <FailureMessage> >(); for (int i = 0; i < 10; i++) { futures.Add(CompletableFuture.supplyAsync(this.collectAuthFailureOnFailedAuth, executor)); } try { // Wait for all tasks to complete CompletableFuture.allOf(futures.ToArray()).get(30, SECONDS); // We want at least one of the futures to fail with our expected code for (int i = 0; i < futures.Count; i++) { FailureMessage recordedMessage = futures[i].get(); if (recordedMessage != null) { failureMessage = recordedMessage; break; } } } catch (TimeoutException) { // if jobs did not complete, let's try again // do nothing } finally { executor.shutdown(); } } assertThat(failureMessage.Status(), equalTo(Org.Neo4j.Kernel.Api.Exceptions.Status_Security.AuthenticationRateLimit)); assertThat(failureMessage.Message(), containsString("The client has provided incorrect authentication details too many times in a row.")); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void stop() throws Throwable public override void Stop() { if (_executor != null) { _executor.shutdown(); _executor.awaitTermination(30, TimeUnit.SECONDS); _executor = null; } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void perform(Action action) throws Exception private void Perform(Action action) { ExecutorService service = Executors.newFixedThreadPool(_lifecycles.Count); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.List<java.util.concurrent.Future<?>> futures = new java.util.ArrayList<>(); IList <Future <object> > futures = new List <Future <object> >(); foreach (Lifecycle lifecycle in _lifecycles) { futures.Add(service.submit(() => { try { action.Act(lifecycle); } catch (Exception e) { throw new Exception(e); } })); } service.shutdown(); if (!service.awaitTermination(_timeout, _unit)) { //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: for (java.util.concurrent.Future<?> future : futures) foreach (Future <object> future in futures) { future.cancel(true); } } Exception exception = null; //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: for (java.util.concurrent.Future<?> future : futures) foreach (Future <object> future in futures) { try { future.get(); } catch (Exception e) when(e is InterruptedException || e is ExecutionException) { if (exception == null) { exception = new Exception(); } exception.addSuppressed(e); } } if (exception != null) { throw exception; } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void shutDownExecutor(java.util.concurrent.ExecutorService executor) throws InterruptedException private void ShutDownExecutor(ExecutorService executor) { executor.shutdown(); bool terminated = executor.awaitTermination(TEST_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); if (!terminated) { throw new System.InvalidOperationException("Rotation execution failed to complete within reasonable time."); } }
/// <summary> /// Stopping warmer process, needs to be synchronised to prevent racing with profiling and heating /// </summary> private void StopWarmer() { lock (this) { if (_executor != null) { _executor.shutdown(); } } }
public static float[] getMedianErrorRates(LangDescriptor language, int maxNumFiles, int trials) { SubsetValidator validator = new SubsetValidator(language.corpusDir, language); IList <InputDocument> documents = Tool.load(validator.allFiles, language); float[] medians = new float[Math.Min(documents.Count, maxNumFiles) + 1]; int ncpu = Runtime.Runtime.availableProcessors(); if (FORCE_SINGLE_THREADED) { ncpu = 2; } ExecutorService pool = Executors.newFixedThreadPool(ncpu - 1); IList <Callable <Void> > jobs = new List <Callable <Void> >(); for (int i = 1; i <= Math.Min(validator.allFiles.Count, maxNumFiles); i++) { // i is corpus subset size //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int corpusSubsetSize = i; int corpusSubsetSize = i; Callable <Void> job = () => { try { IList <float?> errorRates = new List <float?>(); for (int trial = 1; trial <= trials; trial++) { // multiple trials per subset size org.antlr.codebuff.misc.Pair <InputDocument, IList <InputDocument> > sample = validator.selectSample(documents, corpusSubsetSize); Triple <Formatter, float?, float?> results = validate(language, sample.b, sample.a, true, false); // System.out.println(sample.a.fileName+" n="+corpusSubsetSize+": error="+results.c); // System.out.println("\tcorpus =\n\t\t"+Utils.join(sample.b.iterator(), "\n\t\t")); errorRates.Add(results.c); } errorRates.Sort(); int n = errorRates.Count; float median = errorRates[n / 2].Value; Console.WriteLine("median " + language.name + " error rate for n=" + corpusSubsetSize + " is " + median); medians[corpusSubsetSize] = median; } catch (Exception t) { t.printStackTrace(System.err); } return(null); }; jobs.Add(job); } pool.invokeAll(jobs); pool.shutdown(); bool terminated = pool.awaitTermination(60, TimeUnit.MINUTES); return(medians); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldBeConsistentAfterConcurrentWritesAndForces() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldBeConsistentAfterConcurrentWritesAndForces() { ExecutorService executorService = Executors.newCachedThreadPool(); try { for (int attempt = 0; attempt < 100; attempt++) { using (EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction()) { File aFile = new File("contendedFile"); ICollection <Callable <Void> > workers = new List <Callable <Void> >(); for (int i = 0; i < 100; i++) { workers.Add(() => { try { StoreChannel channel = fs.Open(aFile, OpenMode.READ_WRITE); channel.position(channel.size()); WriteLong(channel, 1); } catch (IOException e) { throw new Exception(e); } return(null); }); workers.Add(() => { StoreChannel channel = fs.Open(aFile, OpenMode.READ_WRITE); channel.force(true); return(null); }); } IList <Future <Void> > futures = executorService.invokeAll(workers); foreach (Future <Void> future in futures) { future.get(); } fs.Crash(); VerifyFileIsFullOfLongIntegerOnes(fs.Open(aFile, OpenMode.READ_WRITE)); } } } finally { executorService.shutdown(); } }
public override void Close() { try { _executor.shutdown(); _executor.awaitTermination(10, TimeUnit.SECONDS); } catch (Exception e) { throw new Exception(e); } }
internal void ShutDown() { _executor.shutdown(); try { _executor.awaitTermination(30, TimeUnit.SECONDS); } catch (InterruptedException e) { _shutdownInterrupted = e; } }
private Future <Void> KillDbInSeparateThread() { ExecutorService executor = newSingleThreadExecutor(); Future <Void> result = executor.submit(() => { KillDb(); return(null); }); executor.shutdown(); return(result); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldWorkWhileHavingHeavyConcurrentUpdates() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWorkWhileHavingHeavyConcurrentUpdates() { // given some initial data //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final long[] nodes = repeatCreateNamedPeopleFor(NAMES.length * CREATION_MULTIPLIER); long[] nodes = RepeatCreateNamedPeopleFor(_names.Length * _creationMultiplier); int initialNodes = nodes.Length; int threads = 5; _indexOnlineMonitor.initialize(threads); ExecutorService executorService = Executors.newFixedThreadPool(threads); // when populating while creating //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.internal.kernel.api.IndexReference index = createPersonNameIndex(); IndexReference index = CreatePersonNameIndex(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.Collection<java.util.concurrent.Callable<UpdatesTracker>> jobs = new java.util.ArrayList<>(threads); ICollection <Callable <UpdatesTracker> > jobs = new List <Callable <UpdatesTracker> >(threads); for (int i = 0; i < threads; i++) { jobs.Add(() => ExecuteCreationsDeletionsAndUpdates(nodes, _creationMultiplier)); } IList <Future <UpdatesTracker> > futures = executorService.invokeAll(jobs); // sum result into empty result UpdatesTracker result = new UpdatesTracker(); result.NotifyPopulationCompleted(); foreach (Future <UpdatesTracker> future in futures) { result.Add(future.get()); } AwaitIndexesOnline(); executorService.shutdown(); assertTrue(executorService.awaitTermination(1, TimeUnit.MINUTES)); // then AssertIndexedNodesMatchesStoreNodes(); int seenWhilePopulating = initialNodes + result.CreatedDuringPopulation() - result.DeletedDuringPopulation(); double expectedSelectivity = UNIQUE_NAMES / seenWhilePopulating; AssertCorrectIndexSelectivity(expectedSelectivity, IndexSelectivity(index)); AssertCorrectIndexSize("Tracker had " + result, seenWhilePopulating, IndexSize(index)); int expectedIndexUpdates = result.DeletedAfterPopulation() + result.CreatedAfterPopulation() + result.UpdatedAfterPopulation(); AssertCorrectIndexUpdates("Tracker had " + result, expectedIndexUpdates, IndexUpdates(index)); }
private InterruptedException ShutdownPool(ExecutorService pool, InterruptedException exception) { if (pool != null) { pool.shutdown(); try { pool.awaitTermination(30, TimeUnit.SECONDS); } catch (InterruptedException e) { return(Exceptions.chain(exception, e)); } } return(exception); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void shouldReadCorrectlyWithConcurrentUpdates(TestCoordinator testCoordinator) throws Throwable private void ShouldReadCorrectlyWithConcurrentUpdates(TestCoordinator testCoordinator) { // Readers config int readers = max(1, Runtime.Runtime.availableProcessors() - 1); // Thread communication System.Threading.CountdownEvent readerReadySignal = new System.Threading.CountdownEvent(readers); System.Threading.CountdownEvent readerStartSignal = new System.Threading.CountdownEvent(1); AtomicBoolean endSignal = testCoordinator.EndSignal(); AtomicBoolean failHalt = new AtomicBoolean(); // Readers signal to writer that there is a failure AtomicReference <Exception> readerError = new AtomicReference <Exception>(); // GIVEN _index = CreateIndex(); testCoordinator.Prepare(_index); // WHEN starting the readers RunnableReader readerTask = new RunnableReader(this, testCoordinator, readerReadySignal, readerStartSignal, endSignal, failHalt, readerError); for (int i = 0; i < readers; i++) { _threadPool.submit(readerTask); } // and starting the checkpointer _threadPool.submit(CheckpointThread(endSignal, readerError, failHalt)); // and starting the writer try { Write(testCoordinator, readerReadySignal, readerStartSignal, endSignal, failHalt); } finally { // THEN no reader should have failed by the time we have finished all the scheduled updates. // A successful read means that all results were ordered and we saw all inserted values and // none of the removed values at the point of making the seek call. endSignal.set(true); _threadPool.shutdown(); _threadPool.awaitTermination(10, TimeUnit.SECONDS); if (readerError.get() != null) { //noinspection ThrowFromFinallyBlock throw readerError.get(); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void restartWhileDoingTransactions() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void RestartWhileDoingTransactions() { // given //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster(); Cluster <object> cluster = ClusterRule.startCluster(); // when //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.GraphDatabaseService coreDB = cluster.getCoreMemberById(0).database(); GraphDatabaseService coreDB = cluster.GetCoreMemberById(0).database(); ExecutorService executor = Executors.newCachedThreadPool(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean done = new java.util.concurrent.atomic.AtomicBoolean(false); AtomicBoolean done = new AtomicBoolean(false); executor.execute(() => { while (!done.get()) { try { using (Transaction tx = coreDB.BeginTx()) { Node node = coreDB.CreateNode(label("boo")); node.setProperty("foobar", "baz_bat"); tx.success(); } } catch (Exception e) when(e is AcquireLockTimeoutException || e is WriteOperationsNotAllowedException) { // expected sometimes } } }); Thread.Sleep(500); cluster.RemoveCoreMemberWithServerId(1); cluster.AddCoreMemberWithId(1).start(); Thread.Sleep(500); // then done.set(true); executor.shutdown(); }