//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(expected = IllegalStateException.class) public void shouldNotDropWhileCreating() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotDropWhileCreating() { // GIVEN //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 IndexProxy inner = new IndexProxyAdapter() IndexProxy inner = new IndexProxyAdapterAnonymousInnerClass2(this, latch); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final IndexProxy outer = newContractCheckingIndexProxy(inner); IndexProxy outer = NewContractCheckingIndexProxy(inner); // WHEN RunInSeparateThread(outer.start); try { latch.WaitForAllToStart(); outer.Drop(); } finally { latch.Finish(); } }
//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(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()); }
public static Server CreateHttpServer(DoubleLatch latch, Org.Neo4j.Test.Barrier_Control innerBarrier, int firstBatchSize, int otherBatchSize) { Server server = new Server(0); server.Handler = new AbstractHandlerAnonymousInnerClass(latch, innerBarrier, firstBatchSize, otherBatchSize); return(server); }
public AbstractHandlerAnonymousInnerClass(DoubleLatch latch, Org.Neo4j.Test.Barrier_Control innerBarrier, int firstBatchSize, int otherBatchSize) { this._latch = latch; this._innerBarrier = innerBarrier; this._firstBatchSize = firstBatchSize; this._otherBatchSize = otherBatchSize; }
//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()); }
// Timeout as fallback safety if test deadlocks //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeout = 60_000) public void shouldWaitOnStopUntilTheRunningCheckpointIsDone() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWaitOnStopUntilTheRunningCheckpointIsDone() { // given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicReference<Throwable> ex = new java.util.concurrent.atomic.AtomicReference<>(); AtomicReference <Exception> ex = new AtomicReference <Exception>(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean stoppedCompleted = new java.util.concurrent.atomic.AtomicBoolean(); AtomicBoolean stoppedCompleted = new AtomicBoolean(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.DoubleLatch checkPointerLatch = new org.neo4j.test.DoubleLatch(1); DoubleLatch checkPointerLatch = new DoubleLatch(1); OtherThreadExecutor <Void> otherThreadExecutor = new OtherThreadExecutor <Void>("scheduler stopper", null); CheckPointer checkPointer = new CheckPointerAnonymousInnerClass(this, checkPointerLatch); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final CheckPointScheduler scheduler = new CheckPointScheduler(checkPointer, ioLimiter, jobScheduler, 20L, health); CheckPointScheduler scheduler = new CheckPointScheduler(checkPointer, _ioLimiter, _jobScheduler, 20L, _health); // when scheduler.Start(); Thread runCheckPointer = new Thread(_jobScheduler.runJob); runCheckPointer.Start(); checkPointerLatch.WaitForAllToStart(); otherThreadExecutor.ExecuteDontWait((OtherThreadExecutor.WorkerCommand <Void, Void>)state => { try { scheduler.Stop(); stoppedCompleted.set(true); } catch (Exception throwable) { ex.set(throwable); } return(null); }); otherThreadExecutor.WaitUntilWaiting(details => details.isAt(typeof(CheckPointScheduler), "waitOngoingCheckpointCompletion")); // then assertFalse(stoppedCompleted.get()); checkPointerLatch.Finish(); runCheckPointer.Join(); while (!stoppedCompleted.get()) { Thread.Sleep(1); } otherThreadExecutor.Dispose(); assertNull(ex.get()); }
//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(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowSpecificExceptionOnConcurrentTransactionAccess() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldThrowSpecificExceptionOnConcurrentTransactionAccess() { // given TransactionRegistry registry = new TransactionHandleRegistry(mock(typeof(Clock)), 0, NullLogProvider.Instance); TransitionalPeriodTransactionMessContainer kernel = mock(typeof(TransitionalPeriodTransactionMessContainer)); GraphDatabaseQueryService queryService = mock(typeof(GraphDatabaseQueryService)); TransitionalTxManagementKernelTransaction kernelTransaction = mock(typeof(TransitionalTxManagementKernelTransaction)); when(kernel.NewTransaction(any(typeof(KernelTransaction.Type)), any(typeof(LoginContext)), anyLong())).thenReturn(kernelTransaction); TransactionFacade actions = new TransactionFacade(kernel, null, queryService, registry, NullLogProvider.Instance); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final TransactionHandle transactionHandle = actions.newTransactionHandle(new DisgustingUriScheme(), true, org.neo4j.internal.kernel.api.security.LoginContext.AUTH_DISABLED, -1); TransactionHandle transactionHandle = actions.NewTransactionHandle(new DisgustingUriScheme(), true, LoginContext.AUTH_DISABLED, -1); //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 StatementDeserializer statements = mock(StatementDeserializer.class); StatementDeserializer statements = mock(typeof(StatementDeserializer)); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: when(statements.HasNext()).thenAnswer(invocation => { latch.StartAndWaitForAllToStartAndFinish(); return(false); }); (new Thread(() => { // start and block until finish transactionHandle.Execute(statements, mock(typeof(ExecutionResultSerializer)), mock(typeof(HttpServletRequest))); })).Start(); latch.WaitForAllToStart(); try { // when actions.FindTransactionHandle(DisgustingUriScheme.ParseTxId(transactionHandle.Uri())); fail("should have thrown exception"); } catch (InvalidConcurrentTransactionAccess) { // then we get here } finally { latch.Finish(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeout = 5000) public void shouldWaitOnStopUntilTheRunningCheckpointIsDone() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWaitOnStopUntilTheRunningCheckpointIsDone() { // given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicReference<Throwable> ex = new java.util.concurrent.atomic.AtomicReference<>(); AtomicReference <Exception> ex = new AtomicReference <Exception>(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.DoubleLatch checkPointerLatch = new org.neo4j.test.DoubleLatch(1); DoubleLatch checkPointerLatch = new DoubleLatch(1); RaftLogPruner logPruner = new RaftLogPrunerAnonymousInnerClass(this, Clock.systemUTC(), checkPointerLatch); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final PruningScheduler scheduler = new PruningScheduler(logPruner, jobScheduler, 20L, org.neo4j.logging.NullLogProvider.getInstance()); PruningScheduler scheduler = new PruningScheduler(logPruner, _jobScheduler, 20L, NullLogProvider.Instance); // when scheduler.Start(); Thread runCheckPointer = new Thread(_jobScheduler.runJob); runCheckPointer.Start(); checkPointerLatch.WaitForAllToStart(); Thread stopper = new Thread(() => { try { scheduler.Stop(); } catch (Exception throwable) { ex.set(throwable); } }); stopper.Start(); checkPointerLatch.Finish(); runCheckPointer.Join(); stopper.Join(); assertNull(ex.get()); }
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(); } } }
//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 shouldAllowTerminatingFromADifferentThread() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAllowTerminatingFromADifferentThread() { // GIVEN //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(1); DoubleLatch latch = new DoubleLatch(1); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.api.KernelTransaction transaction = newTransaction(loginContext()); KernelTransaction transaction = NewTransaction(LoginContext()); TransactionInitializer.accept(transaction); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.concurrent.Future<?> terminationFuture = java.util.concurrent.Executors.newSingleThreadExecutor().submit(() -> Future <object> terminationFuture = Executors.newSingleThreadExecutor().submit(() => { latch.WaitForAllToStart(); transaction.MarkForTermination(Status.General.UnknownError); latch.Finish(); }); // WHEN transaction.Success(); latch.StartAndWaitForAllToStartAndFinish(); assertNull(terminationFuture.get(1, TimeUnit.MINUTES)); try { transaction.Close(); fail("Exception expected"); } catch (Exception e) { assertThat(e, instanceOf(typeof(TransactionTerminatedException))); } // THEN verify(TransactionMonitor, times(1)).transactionFinished(false, IsWriteTx); verify(TransactionMonitor, times(1)).transactionTerminated(IsWriteTx); VerifyExtraInteractionWithTheMonitor(TransactionMonitor, IsWriteTx); }
// --------------------- 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(); }
internal HangingListSnapshot(FileUserRepositoryTest outerInstance, DoubleLatch latch, long timestamp, IList <User> values) : base(timestamp, values, true) { this._outerInstance = outerInstance; this.Latch = latch; }
public CheckPointerAnonymousInnerClass(CheckPointSchedulerTest outerInstance, DoubleLatch checkPointerLatch) { this.outerInstance = outerInstance; this._checkPointerLatch = checkPointerLatch; }
internal ThreadedTransaction(NeoInteractionLevel <S> neo, DoubleLatch latch) { this._neo = neo; this._latch = latch; }
public IndexSamplingJobAnonymousInnerClass3(IndexSamplingJobTrackerTest outerInstance, DoubleLatch latch) { this.outerInstance = outerInstance; this._latch = latch; }
public IndexProxyAdapterAnonymousInnerClass2(ContractCheckingIndexProxyTest outerInstance, DoubleLatch latch) { this.outerInstance = outerInstance; this._latch = latch; }
public IndexSamplingJobAnonymousInnerClass4(IndexSamplingJobTrackerTest outerInstance, DoubleLatch latch, AtomicBoolean lastJobExecuted) { this.outerInstance = outerInstance; this._latch = latch; this._lastJobExecuted = lastJobExecuted; }
public IndexSamplingJobAnonymousInnerClass(IndexSamplingJobTrackerTest outerInstance, DoubleLatch latch, AtomicInteger count) { this.outerInstance = outerInstance; this._latch = latch; this._count = count; }
internal LatchedRunnables(DoubleLatch doubleLatch, ThreadStart runBefore, ThreadStart runAfter) { this.DoubleLatch = doubleLatch; this.RunBefore = runBefore; this.RunAfter = runAfter; }
//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()); } }
internal ControlledIndexPopulator(IndexPopulator @delegate, DoubleLatch latch) { this.Delegate = @delegate; this.Latch = latch; }
public RaftLogPrunerAnonymousInnerClass(PruningSchedulerTest outerInstance, UnknownType systemUTC, DoubleLatch checkPointerLatch) : base(null, null, systemUTC) { this.outerInstance = outerInstance; this._checkPointerLatch = checkPointerLatch; }