//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void processNextBatchShouldDrainMaxBatchSizeItemsOnEachCall() public virtual void ProcessNextBatchShouldDrainMaxBatchSizeItemsOnEachCall() { IList <Job> drainedJobs = new List <Job>(); IList <Job> pushedJobs = new List <Job>(); BoltConnection connection = NewConnection(10); doAnswer(inv => ((IList <Job>)drainedJobs).AddRange(inv.getArgument(1))).when(_queueMonitor).drained(same(connection), anyCollection()); for (int i = 0; i < 15; i++) { Job newJob = Jobs.noop(); pushedJobs.Add(newJob); connection.Enqueue(newJob); } connection.ProcessNextBatch(); verify(_queueMonitor).drained(same(connection), anyCollection()); assertEquals(10, drainedJobs.Count); //JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method: assertTrue(drainedJobs.containsAll(pushedJobs.subList(0, 10))); drainedJobs.Clear(); connection.ProcessNextBatch(); verify(_queueMonitor, times(2)).drained(same(connection), anyCollection()); assertEquals(5, drainedJobs.Count); //JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method: assertTrue(drainedJobs.containsAll(pushedJobs.subList(10, 15))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void createdWorkerThreadsShouldContainConnectorName() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void CreatedWorkerThreadsShouldContainConnectorName() { AtomicInteger executeBatchCompletionCount = new AtomicInteger(); AtomicReference <Thread> poolThread = new AtomicReference <Thread>(); AtomicReference <string> poolThreadName = new AtomicReference <string>(); string id = System.Guid.randomUUID().ToString(); BoltConnection connection = NewConnection(id); when(connection.HasPendingJobs()).thenAnswer(inv => { executeBatchCompletionCount.incrementAndGet(); return(false); }); when(connection.ProcessNextBatch()).thenAnswer(inv => { poolThread.set(Thread.CurrentThread); poolThreadName.set(Thread.CurrentThread.Name); return(true); }); _boltScheduler.start(); _boltScheduler.created(connection); _boltScheduler.enqueued(connection, Jobs.noop()); Predicates.await(() => executeBatchCompletionCount.get() > 0, 1, MINUTES); assertThat(poolThread.get().Name, not(equalTo(poolThreadName.get()))); assertThat(poolThread.get().Name, containsString(string.Format("[{0}]", CONNECTOR_KEY))); assertThat(poolThread.get().Name, not(containsString(string.Format("[{0}]", connection.RemoteAddress())))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void createdWorkerThreadsShouldContainConnectorNameAndRemoteAddressInTheirNamesWhenActive() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void CreatedWorkerThreadsShouldContainConnectorNameAndRemoteAddressInTheirNamesWhenActive() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicReference<String> capturedThreadName = new java.util.concurrent.atomic.AtomicReference<>(); AtomicReference <string> capturedThreadName = new AtomicReference <string>(); AtomicInteger processNextBatchCount = new AtomicInteger(); string id = System.Guid.randomUUID().ToString(); BoltConnection connection = NewConnection(id); AtomicBoolean exitCondition = new AtomicBoolean(); when(connection.ProcessNextBatch()).thenAnswer(inv => { capturedThreadName.set(Thread.CurrentThread.Name); processNextBatchCount.incrementAndGet(); return(AwaitExit(exitCondition)); }); _boltScheduler.start(); _boltScheduler.created(connection); _boltScheduler.enqueued(connection, Jobs.noop()); Predicates.await(() => processNextBatchCount.get() > 0, 1, MINUTES); assertThat(capturedThreadName.get(), containsString(string.Format("[{0}]", CONNECTOR_KEY))); assertThat(capturedThreadName.get(), containsString(string.Format("[{0}]", connection.RemoteAddress()))); exitCondition.set(true); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void destroyedShouldCancelActiveWorkItem() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void DestroyedShouldCancelActiveWorkItem() { AtomicInteger processNextBatchCount = new AtomicInteger(); string id = System.Guid.randomUUID().ToString(); BoltConnection connection = NewConnection(id); AtomicBoolean exitCondition = new AtomicBoolean(); when(connection.ProcessNextBatch()).thenAnswer(inv => { processNextBatchCount.incrementAndGet(); return(AwaitExit(exitCondition)); }); _boltScheduler.start(); _boltScheduler.created(connection); _boltScheduler.enqueued(connection, Jobs.noop()); Predicates.await(() => processNextBatchCount.get() > 0, 1, MINUTES); _boltScheduler.closed(connection); Predicates.await(() => !_boltScheduler.isActive(connection), 1, MINUTES); assertFalse(_boltScheduler.isActive(connection)); assertEquals(1, processNextBatchCount.get()); exitCondition.set(true); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void processNextBatchShouldDoNothingIfQueueIsEmptyAndConnectionNotClosed() public virtual void ProcessNextBatchShouldDoNothingIfQueueIsEmptyAndConnectionNotClosed() { BoltConnection connection = NewConnection(); connection.ProcessNextBatch(); verify(_queueMonitor, never()).drained(same(connection), anyCollection()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void stopShouldNotifyListenerOnTheNextBatch() public virtual void StopShouldNotifyListenerOnTheNextBatch() { BoltConnection connection = NewConnection(); connection.Start(); connection.Stop(); connection.ProcessNextBatch(); verify(_connectionListener).closed(connection); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldLogBoltConnectionAuthFatalityError() public virtual void ShouldLogBoltConnectionAuthFatalityError() { BoltConnection connection = NewConnection(); connection.Enqueue(machine => { throw new BoltConnectionAuthFatality(new AuthenticationException(Status.Security.Unauthorized, "inner error")); }); connection.ProcessNextBatch(); verify(_stateMachine).close(); _logProvider.assertExactly(AssertableLogProvider.inLog(containsString(typeof(BoltServer).Assembly.GetName().Name)).warn(containsString("inner error"))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void stopShouldCloseStateMachineOnProcessNextBatch() public virtual void StopShouldCloseStateMachineOnProcessNextBatch() { BoltConnection connection = NewConnection(); connection.Stop(); connection.ProcessNextBatch(); verify(_queueMonitor).enqueued(ArgumentMatchers.eq(connection), any(typeof(Job))); verify(_stateMachine).markForTermination(); verify(_stateMachine).close(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void processNextBatchShouldCloseConnectionOnFatalAuthenticationError() public virtual void ProcessNextBatchShouldCloseConnectionOnFatalAuthenticationError() { BoltConnection connection = NewConnection(); connection.Enqueue(machine => { throw new BoltConnectionAuthFatality("auth failure", new Exception("inner error")); }); connection.ProcessNextBatch(); verify(_stateMachine).close(); _logProvider.assertNone(AssertableLogProvider.inLog(containsString(typeof(BoltServer).Assembly.GetName().Name)).warn(Matchers.any(typeof(string)))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void processNextBatchShouldNotifyQueueMonitorAboutDrain() public virtual void ProcessNextBatchShouldNotifyQueueMonitorAboutDrain() { IList <Job> drainedJobs = new List <Job>(); Job job = Jobs.noop(); BoltConnection connection = NewConnection(); doAnswer(inv => ((IList <Job>)drainedJobs).AddRange(inv.getArgument(1))).when(_queueMonitor).drained(same(connection), anyCollection()); connection.Enqueue(job); connection.ProcessNextBatch(); verify(_queueMonitor).drained(same(connection), anyCollection()); assertTrue(drainedJobs.Contains(job)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void processNextBatchShouldThrowAssertionErrorIfStatementOpen() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ProcessNextBatchShouldThrowAssertionErrorIfStatementOpen() { BoltConnection connection = NewConnection(1); connection.Enqueue(Jobs.noop()); connection.Enqueue(Jobs.noop()); // force to a message waiting loop when(_stateMachine.hasOpenStatement()).thenReturn(true); connection.ProcessNextBatch(); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: _logProvider.assertExactly(AssertableLogProvider.inLog(typeof(DefaultBoltConnection).FullName).error(startsWith("Unexpected error"), isA(typeof(AssertionError)))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void processNextBatchShouldCloseConnectionAndLogOnFatalBoltError() public virtual void ProcessNextBatchShouldCloseConnectionAndLogOnFatalBoltError() { BoltConnectionFatality exception = new BoltProtocolBreachFatality("fatal bolt error"); BoltConnection connection = NewConnection(); connection.Enqueue(machine => { throw exception; }); connection.ProcessNextBatch(); verify(_stateMachine).close(); _logProvider.assertExactly(AssertableLogProvider.inLog(containsString(typeof(BoltServer).Assembly.GetName().Name)).error(containsString("Protocol breach detected in bolt session"), @is(exception))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void processNextBatchShouldCloseConnectionAndLogOnUnexpectedException() public virtual void ProcessNextBatchShouldCloseConnectionAndLogOnUnexpectedException() { Exception exception = new Exception("unexpected exception"); BoltConnection connection = NewConnection(); connection.Enqueue(machine => { throw exception; }); connection.ProcessNextBatch(); verify(_stateMachine).close(); _logProvider.assertExactly(AssertableLogProvider.inLog(containsString(typeof(BoltServer).Assembly.GetName().Name)).error(containsString("Unexpected error detected in bolt session"), @is(exception))); }
private bool ExecuteBatch(BoltConnection connection) { Thread currentThread = Thread.CurrentThread; string originalName = currentThread.Name; string newName = string.Format("{0} [{1}] ", originalName, connection.RemoteAddress()); currentThread.Name = newName; try { return(connection.ProcessNextBatch()); } finally { currentThread.Name = originalName; } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void successfulJobsShouldTriggerSchedulingOfPendingJobs() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void SuccessfulJobsShouldTriggerSchedulingOfPendingJobs() { AtomicInteger counter = new AtomicInteger(); string id = System.Guid.randomUUID().ToString(); BoltConnection connection = NewConnection(id); when(connection.ProcessNextBatch()).thenAnswer(inv => counter.incrementAndGet() > 0); when(connection.HasPendingJobs()).thenReturn(true).thenReturn(false); _boltScheduler.start(); _boltScheduler.created(connection); _boltScheduler.enqueued(connection, Jobs.noop()); Predicates.await(() => counter.get() > 1, 1, MINUTES); verify(connection, times(2)).processNextBatch(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void processNextBatchShouldReturnWhenConnectionIsStopped() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ProcessNextBatchShouldReturnWhenConnectionIsStopped() { BoltConnection connection = NewConnection(1); connection.Enqueue(Jobs.noop()); connection.Enqueue(Jobs.noop()); // force to a message waiting loop when(_stateMachine.shouldStickOnThread()).thenReturn(true); Future <bool> future = OtherThread.execute(state => connection.ProcessNextBatch()); connection.Stop(); OtherThread.get().awaitFuture(future); verify(_stateMachine).close(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void enqueuedShouldScheduleJob() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void EnqueuedShouldScheduleJob() { string id = System.Guid.randomUUID().ToString(); AtomicBoolean exitCondition = new AtomicBoolean(); BoltConnection connection = NewConnection(id); when(connection.ProcessNextBatch()).thenAnswer(inv => AwaitExit(exitCondition)); _boltScheduler.start(); _boltScheduler.created(connection); _boltScheduler.enqueued(connection, Jobs.noop()); Predicates.await(() => _boltScheduler.isActive(connection), 1, MINUTES); exitCondition.set(true); Predicates.await(() => !_boltScheduler.isActive(connection), 1, MINUTES); verify(connection).processNextBatch(); }