//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(); } }
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()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testConcurrentIsUserAuthorized() throws Exception public virtual void testConcurrentIsUserAuthorized() { int threadCount = 2; int invocationCount = 500; ExecutorService executorService = Executors.newFixedThreadPool(threadCount); try { List <Callable <Exception> > callables = new List <Callable <Exception> >(); for (int i = 0; i < invocationCount; i++) { callables.Add(new CallableAnonymousInnerClass(this)); } IList <Future <Exception> > futures = executorService.invokeAll(callables); foreach (Future <Exception> future in futures) { Exception exception = future.get(); if (exception != null) { fail("No exception expected: " + exception.Message); } } } finally { // reset original logging level executorService.shutdownNow(); executorService.awaitTermination(10, TimeUnit.SECONDS); } }
//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 WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void stop() throws Throwable public override void Stop() { _msgLog.debug("Shutting down NetworkSender"); foreach (ExecutorService executorService in _senderExecutors.Values) { executorService.shutdown(); } long totalWaitTime = 0; long maxWaitTime = SECONDS.toMillis(5); foreach (KeyValuePair <URI, ExecutorService> entry in _senderExecutors.SetOfKeyValuePairs()) { URI targetAddress = entry.Key; ExecutorService executorService = entry.Value; long start = currentTimeMillis(); if (!executorService.awaitTermination(maxWaitTime - totalWaitTime, MILLISECONDS)) { _msgLog.warn("Could not shut down send executor towards: " + targetAddress); break; } totalWaitTime += currentTimeMillis() - start; } _senderExecutors.Clear(); _channels.close().awaitUninterruptibly(); _clientBootstrap.releaseExternalResources(); _msgLog.debug("Shutting down NetworkSender for " + ToString(_config) + " complete"); }
//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 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(), "[]"); } }
//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 } }
//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 TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void runTest() throws InterruptedException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void RunTest() { for (int i = 0; i < N_THREADS; i++) { _service.submit(_task); } _service.awaitTermination(10, TimeUnit.SECONDS); assertThat(_counter.get(), equalTo(N_THREADS)); }
//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."); } }
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); }
public override void Close() { try { _executor.shutdown(); _executor.awaitTermination(10, TimeUnit.SECONDS); } catch (Exception e) { throw new Exception(e); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static java.util.concurrent.ExecutorService sameThreadExecutor() throws InterruptedException private static ExecutorService SameThreadExecutor() { ExecutorService executor = ImmediateExecutor(); when(executor.awaitTermination(anyLong(), any())).thenReturn(true); doAnswer(invocation => { (( ThreadStart )invocation.getArgument(0)).run(); return(null); }).when(executor).execute(any()); return(executor); }
internal void ShutDown() { _executor.shutdown(); try { _executor.awaitTermination(30, TimeUnit.SECONDS); } catch (InterruptedException e) { _shutdownInterrupted = e; } }
//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)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRun() throws InterruptedException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldRun() { ExecutorService service = Executors.newFixedThreadPool(3); service.submit(_createUserWork); service.submit(_deleteUserWork); service.submit(_transactionWork); service.awaitTermination(30, TimeUnit.SECONDS); string msg = string.join(Environment.NewLine, _errors.Select(Exception.getMessage).ToList()); assertThat(msg, _errors, empty()); }
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 shouldOnlyAllowOneThreadPerInterval() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldOnlyAllowOneThreadPerInterval() { // given int intervalMillis = 10; int nThreads = 10; int iterations = 100; FakeClock clock = Clocks.fakeClock(); System.Action <ThreadStart> cap = rateLimiter(Duration.ofMillis(intervalMillis), clock); AtomicInteger cnt = new AtomicInteger(); ThreadStart op = cnt.incrementAndGet; for (int iteration = 1; iteration <= iterations; iteration++) { // given clock.Forward(intervalMillis, MILLISECONDS); System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1); ExecutorService es = Executors.newCachedThreadPool(); for (int j = 0; j < nThreads; j++) { es.submit(() => { try { latch.await(); } catch (InterruptedException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } cap(op); }); } // when latch.Signal(); es.shutdown(); es.awaitTermination(10, SECONDS); // then assertThat(cnt.get(), equalTo(iteration)); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void execute(java.util.List<RecordStresser> recordStressers) throws InterruptedException, java.util.concurrent.ExecutionException private void Execute(IList <RecordStresser> recordStressers) { ExecutorService executorService = Executors.newFixedThreadPool(_numberOfThreads, r => { Thread thread = Executors.defaultThreadFactory().newThread(r); thread.Daemon = true; return(thread); }); IList <Future <Void> > futures = executorService.invokeAll(recordStressers); foreach (Future <Void> future in futures) { future.get(); } executorService.shutdown(); assertTrue(executorService.awaitTermination(10, TimeUnit.SECONDS)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static long importData(String title, int numRunners, InputIterable data, org.neo4j.unsafe.impl.batchimport.store.BatchingNeoStores stores, System.Func<EntityImporter> visitors, org.neo4j.unsafe.impl.batchimport.staging.ExecutionMonitor executionMonitor, org.neo4j.unsafe.impl.batchimport.stats.StatsProvider memoryStatsProvider) throws java.io.IOException private static long ImportData(string title, int numRunners, InputIterable data, BatchingNeoStores stores, System.Func <EntityImporter> visitors, ExecutionMonitor executionMonitor, StatsProvider memoryStatsProvider) { LongAdder roughEntityCountProgress = new LongAdder(); ExecutorService pool = Executors.newFixedThreadPool(numRunners, new NamedThreadFactory(title + "Importer")); IoMonitor writeMonitor = new IoMonitor(stores.IoTracer); ControllableStep step = new ControllableStep(title, roughEntityCountProgress, Configuration.DEFAULT, writeMonitor, memoryStatsProvider); StageExecution execution = new StageExecution(title, null, Configuration.DEFAULT, Collections.singletonList(step), 0); long startTime = currentTimeMillis(); using (InputIterator dataIterator = data.GetEnumerator()) { executionMonitor.Start(execution); for (int i = 0; i < numRunners; i++) { pool.submit(new ExhaustingEntityImporterRunnable(execution, dataIterator, visitors(), roughEntityCountProgress)); } pool.shutdown(); long nextWait = 0; try { while (!pool.awaitTermination(nextWait, TimeUnit.MILLISECONDS)) { executionMonitor.Check(execution); nextWait = executionMonitor.NextCheckTime() - currentTimeMillis(); } } catch (InterruptedException e) { Thread.CurrentThread.Interrupt(); throw new IOException(e); } } execution.AssertHealthy(); step.MarkAsCompleted(); writeMonitor.Stop(); executionMonitor.End(execution, currentTimeMillis() - startTime); execution.AssertHealthy(); return(roughEntityCountProgress.sum()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void notifyWithExecutorAndNotification() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void NotifyWithExecutorAndNotification() { string message = "foo"; string threadNamePrefix = "test-thread"; Listener listener1 = new Listener(); Listener listener2 = new Listener(); Listeners <Listener> listeners = NewListeners(listener1, listener2); ExecutorService executor = newSingleThreadExecutor(named(threadNamePrefix)); listeners.Notify(executor, listener => listener.process(message)); executor.shutdown(); executor.awaitTermination(1, TimeUnit.MINUTES); assertEquals(message, listener1.Message); assertThat(listener1.ThreadName, startsWith(threadNamePrefix)); assertEquals(message, listener2.Message); assertThat(listener2.ThreadName, startsWith(threadNamePrefix)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void consume(String name, org.neo4j.unsafe.impl.batchimport.InputIterator entities, org.neo4j.unsafe.impl.batchimport.input.csv.Header header, Deserializer deserializer) throws java.io.IOException private void Consume(string name, InputIterator entities, Header header, Deserializer deserializer) { using (PrintStream @out = File(name + "header.csv")) { Serialize(@out, header); } try { int threads = Runtime.Runtime.availableProcessors(); ExecutorService executor = Executors.newFixedThreadPool(threads); for (int i = 0; i < threads; i++) { int id = i; executor.submit((Callable <Void>)() => { StringDeserialization deserialization = new StringDeserialization(_config); using (PrintStream @out = File(name + "-" + id + ".csv"), InputChunk chunk = entities.NewChunk()) { InputEntity entity = new InputEntity(); while (entities.Next(chunk)) { while (chunk.next(entity)) { @out.println(deserializer.Apply(entity, deserialization, header)); } } } return(null); }); } executor.shutdown(); executor.awaitTermination(10, TimeUnit.MINUTES); } catch (InterruptedException e) { Thread.CurrentThread.Interrupt(); throw new IOException(e); } }
public int computeItemSimilarities(int degreeOfParallelism, int maxDurationInHours, SimilarItemsWriter writer) { ExecutorService executorService = Executors.newFixedThreadPool(degreeOfParallelism + 1); Output output = null; try { writer.open(); DataModel dataModel = getRecommender().getDataModel(); BlockingQueue<long[]> itemsIDsInBatches = queueItemIDsInBatches(dataModel, batchSize); BlockingQueue<List<SimilarItems>> results = new LinkedBlockingQueue<List<SimilarItems>>(); AtomicInteger numActiveWorkers = new AtomicInteger(degreeOfParallelism); for (int n = 0; n < degreeOfParallelism; n++) { executorService.execute(new SimilarItemsWorker(n, itemsIDsInBatches, results, numActiveWorkers)); } output = new Output(results, writer, numActiveWorkers); executorService.execute(output); } catch (Exception e) { throw new IOException(e); } finally { executorService.shutdown(); try { bool succeeded = executorService.awaitTermination(maxDurationInHours, TimeUnit.HOURS); if (!succeeded) { throw new RuntimeException("Unable to complete the computation in " + maxDurationInHours + " hours!"); } } catch (InterruptedException e) { throw new RuntimeException(e); } Closeables.close(writer, false); } return output.getNumSimilaritiesProcessed(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void backupMultipleSchemaIndexes() throws InterruptedException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void BackupMultipleSchemaIndexes() { // given ExecutorService executorService = Executors.newSingleThreadExecutor(); AtomicBoolean end = new AtomicBoolean(); int backupPort = PortAuthority.allocatePort(); GraphDatabaseService db = GetEmbeddedTestDataBaseService(backupPort); try { int numberOfIndexedLabels = 10; IList <Label> indexedLabels = CreateIndexes(db, numberOfIndexedLabels); // start thread that continuously writes to indexes executorService.submit(() => { while (!end.get()) { using (Transaction tx = Db.beginTx()) { Db.createNode(indexedLabels[_random.Next(numberOfIndexedLabels)]).setProperty("prop", _random.nextValue()); tx.success(); } } }); executorService.shutdown(); // create backup OnlineBackup backup = OnlineBackup.From("127.0.0.1", backupPort).full(_backupDatabasePath.Path); assertTrue("Should be consistent", backup.Consistent); end.set(true); executorService.awaitTermination(1, TimeUnit.MINUTES); } finally { Db.shutdown(); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void populateDbAndIndexes(int nodeCount, boolean multiThreaded) throws InterruptedException private void PopulateDbAndIndexes(int nodeCount, bool multiThreaded) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.GraphDatabaseService db = new org.neo4j.test.TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(directory.databaseDir()).setConfig(org.neo4j.graphdb.factory.GraphDatabaseSettings.multi_threaded_schema_index_population_enabled, multiThreaded + "").newGraphDatabase(); GraphDatabaseService db = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(_directory.databaseDir()).setConfig(GraphDatabaseSettings.multi_threaded_schema_index_population_enabled, multiThreaded + "").newGraphDatabase(); try { CreateIndexes(db); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean(); AtomicBoolean end = new AtomicBoolean(); ExecutorService executor = _cleanup.add(Executors.newCachedThreadPool()); for (int i = 0; i < 10; i++) { executor.submit(() => { RandomValues randomValues = RandomValues.create(); while (!end.get()) { ChangeRandomNode(db, nodeCount, randomValues); } }); } while (!IndexesAreOnline(db)) { Thread.Sleep(100); } end.set(true); executor.shutdown(); executor.awaitTermination(10, SECONDS); } finally { Db.shutdown(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void executorShutdownAfterStoreScanCompletes() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ExecutorShutdownAfterStoreScanCompletes() { EntityUpdates update = NodeUpdates(1, PROPERTY_ID, "foo", LABEL_ID); IndexStoreView storeView = NewStoreView(update); ExecutorService executor = ImmediateExecutor(); when(executor.awaitTermination(anyLong(), any())).thenReturn(true); BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, executor, NullLogProvider.Instance, mock(typeof(SchemaState))); StoreScan <IndexPopulationFailedKernelException> storeScan = batchingPopulator.IndexAllEntities(); verify(executor, never()).shutdown(); storeScan.Run(); verify(executor, never()).shutdown(); verify(executor, never()).awaitTermination(anyLong(), any()); batchingPopulator.Close(true); verify(executor).shutdown(); verify(executor).awaitTermination(anyLong(), any()); }