Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPerformSuccessfulStoreCopyProcess() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPerformSuccessfulStoreCopyProcess()
        {
            // given
            StoreStreamingProcess process = new StoreStreamingProcess(_protocol, _checkPointerSupplier, _mutex, _resourceStream);

            // mocked behaviour
            ImmediateEventExecutor eventExecutor     = ImmediateEventExecutor.INSTANCE;
            Promise <Void>         completionPromise = eventExecutor.newPromise();
            long lastCheckpointedTxId = 1000L;
            RawCursor <StoreResource, IOException> resources = rawCursorOf();

            when(_checkPointer.tryCheckPoint(any())).thenReturn(lastCheckpointedTxId);
            when(_checkPointer.lastCheckPointedTransactionId()).thenReturn(lastCheckpointedTxId);
            when(_protocol.end(_ctx, SUCCESS)).thenReturn(completionPromise);
            when(_resourceStream.create()).thenReturn(resources);

            // when
            process.Perform(_ctx);

            // then
            InOrder inOrder = Mockito.inOrder(_protocol, _checkPointer);

            inOrder.verify(_checkPointer).tryCheckPoint(any());
            inOrder.verify(_protocol).end(_ctx, SUCCESS);
            inOrder.verifyNoMoreInteractions();

            assertEquals(1, @lock.ReadLockCount);

            // when
            completionPromise.Success = null;

            // then
            assertEquals(0, @lock.ReadLockCount);
        }
Example #2
0
 /// <summary>
 /// Chains a channel future to a promise. Used when the returned promise
 /// was not allocated through the channel and cannot be used as the
 /// first-hand promise for the I/O operation.
 /// </summary>
 private static void Chain(ChannelFuture when, Promise <Void> then)
 {
     when.addListener(f =>
     {
         if (f.Success)
         {
             then.Success = when.get();
         }
         else
         {
             then.Failure = when.cause();
         }
     });
 }
Example #3
0
 /// <summary>
 /// Will try to reconnect once before giving up on a send. The reconnection *must* happen
 /// after write was scheduled. This is necessary to provide proper ordering when a message
 /// is sent right after the non-blocking channel was setup and before the server is ready
 /// to accept a connection. This happens frequently in tests.
 /// </summary>
 private void DeferredWrite(object msg, ChannelFuture channelFuture, Promise <Void> promise, bool firstAttempt, System.Action <io.netty.channel.Channel, object> writer)
 {
     channelFuture.addListener((ChannelFutureListener)f =>
     {
         if (f.Success)
         {
             writer(f.channel(), msg);
         }
         else if (firstAttempt)
         {
             TryConnect();
             DeferredWrite(msg, _fChannel, promise, false, writer);
         }
         else
         {
             promise.Failure = f.cause();
         }
     });
 }
Example #4
0
        private Future <Void> Write(object msg, bool flush)
        {
            if (_disposed)
            {
                throw new System.InvalidOperationException("sending on disposed channel");
            }

            if (_channel.Active)
            {
                if (flush)
                {
                    return(_channel.writeAndFlush(msg));
                }
                else
                {
                    return(_channel.write(msg));
                }
            }
            else
            {
                Promise <Void> promise = _eventLoop.newPromise();
                System.Action <io.netty.channel.Channel, object> writer;

                if (flush)
                {
                    writer = (_channel, message) => chain(_channel.writeAndFlush(msg), promise);
                }
                else
                {
                    writer = (_channel, message) => chain(_channel.write(msg), promise);
                }

                DeferredWrite(msg, _fChannel, promise, true, writer);
                return(promise);
            }
        }