//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotRunASampleJobWhichIsAlreadyRunning() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotRunASampleJobWhichIsAlreadyRunning() { // given when(_config.jobLimit()).thenReturn(2); JobScheduler jobScheduler = createInitialisedScheduler(); IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(_config, jobScheduler); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.DoubleLatch latch = new org.neo4j.test.DoubleLatch(); DoubleLatch latch = new DoubleLatch(); // when //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger count = new java.util.concurrent.atomic.AtomicInteger(0); AtomicInteger count = new AtomicInteger(0); assertTrue(jobTracker.CanExecuteMoreSamplingJobs()); IndexSamplingJob job = new IndexSamplingJobAnonymousInnerClass(this, latch, count); jobTracker.ScheduleSamplingJob(job); jobTracker.ScheduleSamplingJob(job); latch.StartAndWaitForAllToStart(); latch.WaitForAllToFinish(); assertEquals(1, count.get()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotKillQueryIfNotAuthenticated() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotKillQueryIfNotAuthenticated() { EnterpriseLoginContext unAuthSubject = CreateFakeAnonymousEnterpriseLoginContext(); GraphDatabaseFacade graph = Neo.LocalGraph; DoubleLatch latch = new DoubleLatch(2); ThreadedTransaction <EnterpriseLoginContext> read = new ThreadedTransaction <EnterpriseLoginContext>(Neo, latch); string query = read.Execute(ThreadingConflict, ReadSubject, "UNWIND [1,2,3] AS x RETURN x"); latch.StartAndWaitForAllToStart(); string id = ExtractQueryId(query); try { using (InternalTransaction tx = graph.BeginTransaction(KernelTransaction.Type.@explicit, unAuthSubject)) { graph.execute(tx, "CALL dbms.killQuery('" + id + "')", EMPTY_MAP); throw new AssertionError("Expected exception to be thrown"); } } catch (QueryExecutionException e) { assertThat(e.Message, containsString(PERMISSION_DENIED)); } latch.FinishAndWaitForAllToFinish(); read.CloseAndAssertSuccess(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeout = 5_000) public void shouldAcceptNewJobWhenRunningJobFinishes() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAcceptNewJobWhenRunningJobFinishes() { // Given when(_config.jobLimit()).thenReturn(1); JobScheduler jobScheduler = createInitialisedScheduler(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(config, jobScheduler); IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(_config, jobScheduler); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.DoubleLatch latch = new org.neo4j.test.DoubleLatch(); DoubleLatch latch = new DoubleLatch(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean lastJobExecuted = new java.util.concurrent.atomic.AtomicBoolean(); AtomicBoolean lastJobExecuted = new AtomicBoolean(); jobTracker.ScheduleSamplingJob(new IndexSamplingJobAnonymousInnerClass3(this, latch)); // When Executors.newSingleThreadExecutor().execute(() => { jobTracker.WaitUntilCanExecuteMoreSamplingJobs(); jobTracker.ScheduleSamplingJob(new IndexSamplingJobAnonymousInnerClass4(this, latch, lastJobExecuted)); }); assertFalse(jobTracker.CanExecuteMoreSamplingJobs()); latch.StartAndWaitForAllToStart(); latch.WaitForAllToFinish(); // Then assertTrue(lastJobExecuted.get()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotStartOtherSamplingWhenSamplingAllTheIndexes() public virtual void ShouldNotStartOtherSamplingWhenSamplingAllTheIndexes() { // given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger totalCount = new java.util.concurrent.atomic.AtomicInteger(0); AtomicInteger totalCount = new AtomicInteger(0); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger concurrentCount = new java.util.concurrent.atomic.AtomicInteger(0); AtomicInteger concurrentCount = new AtomicInteger(0); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.DoubleLatch jobLatch = new org.neo4j.test.DoubleLatch(); DoubleLatch jobLatch = new DoubleLatch(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.DoubleLatch testLatch = new org.neo4j.test.DoubleLatch(); DoubleLatch testLatch = new DoubleLatch(); IndexSamplingJobFactory jobFactory = (_indexId, proxy) => { if (!concurrentCount.compareAndSet(0, 1)) { throw new System.InvalidOperationException("count !== 0 on create"); } totalCount.incrementAndGet(); jobLatch.WaitForAllToStart(); testLatch.StartAndWaitForAllToStart(); jobLatch.WaitForAllToFinish(); concurrentCount.decrementAndGet(); testLatch.Finish(); return(null); }; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final IndexSamplingController controller = new IndexSamplingController(samplingConfig, jobFactory, jobQueue, tracker, snapshotProvider, scheduler, always(true)); IndexSamplingController controller = new IndexSamplingController(_samplingConfig, jobFactory, _jobQueue, _tracker, _snapshotProvider, _scheduler, Always(true)); when(_tracker.canExecuteMoreSamplingJobs()).thenReturn(true); when(_indexProxy.State).thenReturn(ONLINE); // when running once (new Thread(RunController(controller, TRIGGER_REBUILD_UPDATED))).Start(); jobLatch.StartAndWaitForAllToStart(); testLatch.WaitForAllToStart(); // then blocking on first job assertEquals(1, concurrentCount.get()); // when running a second time controller.SampleIndexes(BACKGROUND_REBUILD_UPDATED); // then no concurrent job execution jobLatch.Finish(); testLatch.WaitForAllToFinish(); // and finally exactly one job has run to completion assertEquals(0, concurrentCount.get()); assertEquals(1, totalCount.get()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void assertKeepAuthorizationForLifetimeOfTransaction(String username, System.Action<org.neo4j.driver.v1.Transaction> assertion) throws Throwable private void AssertKeepAuthorizationForLifetimeOfTransaction(string username, System.Action <Transaction> assertion) { DoubleLatch latch = new DoubleLatch(2); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Throwable[] threadFail = {null}; Exception[] threadFail = new Exception[] { null }; Thread readerThread = new Thread(() => { try { using (Driver driver = ConnectDriver(username, "abc123"), Session session = driver.session(), Transaction tx = session.beginTransaction()) { assertion(tx); latch.StartAndWaitForAllToStart(); latch.FinishAndWaitForAllToFinish(); assertion(tx); tx.success(); } } catch (Exception t) { threadFail[0] = t; // Always release the latch so we get the failure in the main thread latch.Start(); latch.Finish(); } }); readerThread.Start(); latch.StartAndWaitForAllToStart(); ClearAuthCacheFromDifferentConnection(); latch.FinishAndWaitForAllToFinish(); readerThread.Join(); if (threadFail[0] != null) { throw threadFail[0]; } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotAcceptMoreJobsThanAllowed() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotAcceptMoreJobsThanAllowed() { // given when(_config.jobLimit()).thenReturn(1); JobScheduler jobScheduler = createInitialisedScheduler(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(config, jobScheduler); IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(_config, jobScheduler); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.DoubleLatch latch = new org.neo4j.test.DoubleLatch(); DoubleLatch latch = new DoubleLatch(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.DoubleLatch waitingLatch = new org.neo4j.test.DoubleLatch(); DoubleLatch waitingLatch = new DoubleLatch(); // when assertTrue(jobTracker.CanExecuteMoreSamplingJobs()); jobTracker.ScheduleSamplingJob(new IndexSamplingJobAnonymousInnerClass2(this, latch)); // then latch.WaitForAllToStart(); assertFalse(jobTracker.CanExecuteMoreSamplingJobs()); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean waiting = new java.util.concurrent.atomic.AtomicBoolean(false); AtomicBoolean waiting = new AtomicBoolean(false); (new Thread(() => { waiting.set(true); waitingLatch.StartAndWaitForAllToStart(); jobTracker.WaitUntilCanExecuteMoreSamplingJobs(); waiting.set(false); waitingLatch.Finish(); })).Start(); waitingLatch.WaitForAllToStart(); assertTrue(waiting.get()); latch.Finish(); waitingLatch.WaitForAllToFinish(); assertFalse(waiting.get()); // eventually we accept new jobs while (!jobTracker.CanExecuteMoreSamplingJobs()) { Thread.yield(); } }
public virtual void Loop() { DoubleLatch latch = VolatileLatch; if (latch != null) { latch.StartAndWaitForAllToStart(); } try { //noinspection InfiniteLoopStatement while (true) { try { Thread.Sleep(250); } catch (InterruptedException) { Thread.interrupted(); } Guard.check(); } } catch (Exception e) when(e is TransactionTerminatedException || e is TransactionGuardException) { if (e.status().Equals(TransactionTimedOut)) { throw new TransactionGuardException(TransactionTimedOut, PROCEDURE_TIMEOUT_ERROR, e); } else { throw e; } } finally { if (latch != null) { latch.Finish(); } } }
// --------------------- helpers ----------------------- //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: void shouldTerminateTransactionsForUser(S subject, String procedure) throws Throwable internal virtual void ShouldTerminateTransactionsForUser(S subject, string procedure) { DoubleLatch latch = new DoubleLatch(2); ThreadedTransaction <S> userThread = new ThreadedTransaction <S>(Neo, latch); userThread.ExecuteCreateNode(Threading(), subject); latch.StartAndWaitForAllToStart(); AssertEmpty(AdminSubject, "CALL " + format(procedure, Neo.nameOf(subject))); IDictionary <string, long> transactionsByUser = CountTransactionsByUsername(); assertThat(transactionsByUser[Neo.nameOf(subject)], equalTo(null)); latch.FinishAndWaitForAllToFinish(); userThread.CloseAndAssertExplicitTermination(); AssertEmpty(AdminSubject, "MATCH (n:Test) RETURN n.name AS name"); }
/* * Admin creates user Henrik with password bar * Admin adds user Henrik to role Publisher * Henrik logs in with correct password * Henrik starts transaction with long running writing query Q * Admin removes user Henrik from role Publisher (while Q still running) * Q finishes and transaction is committed → ok * Henrik starts new transaction with write query → permission denied */ //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void roleManagement5() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void RoleManagement5() { AssertEmpty(AdminSubject, "CALL dbms.security.createUser('Henrik', 'bar', false)"); AssertEmpty(AdminSubject, "CALL dbms.security.addRoleToUser('" + PUBLISHER + "', 'Henrik')"); S henrik = Neo.login("Henrik", "bar"); Neo.assertAuthenticated(henrik); DoubleLatch latch = new DoubleLatch(2); ThreadedTransaction <S> write = new ThreadedTransaction <S>(Neo, latch); write.ExecuteCreateNode(ThreadingConflict, henrik); latch.StartAndWaitForAllToStart(); AssertEmpty(AdminSubject, "CALL dbms.security.removeRoleFromUser('" + PUBLISHER + "', 'Henrik')"); latch.FinishAndWaitForAllToFinish(); write.CloseAndAssertSuccess(); TestFailWrite(henrik); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldProvideRolesByUsernameEvenIfMidSetRoles() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldProvideRolesByUsernameEvenIfMidSetRoles() { // Given _roleRepository = new FileRoleRepository(_fs, _roleFile, _logProvider); _roleRepository.create(new RoleRecord("admin", "oskar")); DoubleLatch latch = new DoubleLatch(2); // When Future <object> setUsers = Threading.execute(o => { _roleRepository.Roles = new HangingListSnapshot(this, latch, 10L, java.util.Collections.emptyList()); return(null); }, null); latch.StartAndWaitForAllToStart(); // Then assertThat(_roleRepository.getRoleNamesByUsername("oskar"), containsInAnyOrder("admin")); latch.Finish(); setUsers.get(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldProvideUserByUsernameEvenIfMidSetUsers() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldProvideUserByUsernameEvenIfMidSetUsers() { // Given FileUserRepository users = new FileUserRepository(_fs, _authFile, _logProvider); users.Create((new User.Builder("oskar", LegacyCredential.ForPassword("hidden"))).build()); DoubleLatch latch = new DoubleLatch(2); // When Future <object> setUsers = Threading.execute(o => { users.Users = new HangingListSnapshot(this, latch, 10L, java.util.Collections.emptyList()); return(null); }, null); latch.StartAndWaitForAllToStart(); // Then assertNotNull(users.GetUserByName("oskar")); latch.Finish(); setUsers.get(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeout = 10_000) public void shouldBlockUniqueIndexSeekFromCompetingTransaction() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBlockUniqueIndexSeekFromCompetingTransaction() { // This is the interleaving that we are trying to verify works correctly: // ---------------------------------------------------------------------- // Thread1 (main) : Thread2 // create unique node : // lookup(node) : // open start latch -----> // | : lookup(node) // wait for T2 to block : | // : *block* // commit ---------------> *unblock* // wait for T2 end latch : | // : finish transaction // : open end latch // *unblock* <-------------‘ // assert that we complete before timeout //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.DoubleLatch latch = new org.neo4j.test.DoubleLatch(); DoubleLatch latch = new DoubleLatch(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.internal.kernel.api.IndexReference index = createUniquenessConstraint(labelId, propertyId1); IndexReference index = CreateUniquenessConstraint(_labelId, _propertyId1); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.values.storable.Value value = org.neo4j.values.storable.Values.of("value"); Value value = Values.of("value"); Write write = DataWriteInNewTransaction(); long nodeId = write.NodeCreate(); write.NodeAddLabel(nodeId, _labelId); // This adds the node to the unique index and should take an index write lock write.NodeSetProperty(nodeId, _propertyId1, value); ThreadStart runnableForThread2 = () => { latch.WaitForAllToStart(); try { using (Transaction tx = Kernel.beginTransaction(Transaction.Type.@implicit, LoginContext.AUTH_DISABLED)) { tx.dataRead().lockingNodeUniqueIndexSeek(index, exact(_propertyId1, value)); tx.success(); } } catch (KernelException e) { throw new Exception(e); } finally { latch.Finish(); } }; Thread thread2 = new Thread(runnableForThread2, "Transaction Thread 2"); thread2.Start(); latch.StartAndWaitForAllToStart(); while ((thread2.State != Thread.State.TIMED_WAITING) && (thread2.State != Thread.State.WAITING)) { Thread.yield(); } Commit(); latch.WaitForAllToFinish(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldTerminateQueriesEvenIfUsingPeriodicCommit() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldTerminateQueriesEvenIfUsingPeriodicCommit() { // Spawns a throttled HTTP server, runs a PERIODIC COMMIT that fetches data from this server, // and checks that the query able to be terminated // We start with 3, because that is how many actors we have - // 1. the http server // 2. the running query // 3. the one terminating 2 //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.DoubleLatch latch = new org.neo4j.test.DoubleLatch(3, true); DoubleLatch latch = new DoubleLatch(3, true); // This is used to block the http server between the first and second batch //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.Barrier_Control barrier = new org.neo4j.test.Barrier_Control(); Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control(); // Serve CSV via local web server, let Jetty find a random port for us Server server = CreateHttpServer(latch, barrier, 20, 30); server.start(); int localPort = GetLocalPort(server); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.bolt.runtime.BoltStateMachine[] machine = {null}; BoltStateMachine[] machine = new BoltStateMachine[] { null }; Thread thread = new Thread(() => { try { using (BoltStateMachine stateMachine = Env.newMachine(_boltChannel)) { machine[0] = stateMachine; stateMachine.process(new InitMessage(USER_AGENT, emptyMap()), nullResponseHandler()); string query = format("USING PERIODIC COMMIT 10 LOAD CSV FROM 'http://localhost:%d' AS line " + "CREATE (n:A {id: line[0], square: line[1]}) " + "WITH count(*) as number " + "CREATE (n:ShouldNotExist)", localPort); try { latch.Start(); stateMachine.process(new RunMessage(query, EMPTY_MAP), nullResponseHandler()); stateMachine.process(PullAllMessage.INSTANCE, nullResponseHandler()); } finally { latch.Finish(); } } } catch (BoltConnectionFatality connectionFatality) { throw new Exception(connectionFatality); } }); thread.Name = "query runner"; thread.Start(); // We block this thread here, waiting for the http server to spin up and the running query to get started latch.StartAndWaitForAllToStart(); Thread.Sleep(1000); // This is the call that RESETs the Bolt connection and will terminate the running query machine[0].Process(ResetMessage.INSTANCE, nullResponseHandler()); barrier.Release(); // We block again here, waiting for the running query to have been terminated, and for the server to have // wrapped up and finished streaming http results latch.FinishAndWaitForAllToFinish(); // And now we check that the last node did not get created using (Transaction ignored = Env.graph().beginTx()) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse("Query was not terminated in time - nodes were created!", Env.graph().findNodes(Label.label("ShouldNotExist")).hasNext()); } }