private BoltConnection NewConnection(string id)
        {
            BoltConnection result = mock(typeof(BoltConnection));

            when(result.Id()).thenReturn(id);
            when(result.RemoteAddress()).thenReturn(new InetSocketAddress("localhost", 32_000));
            return(result);
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
//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()))));
        }
Exemplo n.º 4
0
//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);
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void remoteAddressShouldReturnBoltClientAddress()
        public virtual void RemoteAddressShouldReturnBoltClientAddress()
        {
            BoltConnection connection = NewConnection();

            assertEquals(_boltChannel.clientAddress(), connection.RemoteAddress());
        }