Exemple #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void raftIndexIsRecorded() throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RaftIndexIsRecorded()
        {
            // given
            int  txLockSessionId     = Org.Neo4j.Kernel.impl.locking.Locks_Client_Fields.NO_LOCK_SESSION_ID;
            long anyTransactionId    = 1234;
            long lastCommittedIndex  = 1357;
            long updatedCommandIndex = 2468;

            // and
            ReplicatedTransactionStateMachine stateMachine = new ReplicatedTransactionStateMachine(_commandIndexTracker, LockState(txLockSessionId), _batchSize, _logProvider, Org.Neo4j.Io.pagecache.tracing.cursor.PageCursorTracerSupplier_Fields.Null, EmptyVersionContextSupplier.EMPTY);

            ReplicatedTransaction replicatedTransaction = ReplicatedTransaction.from(PhysicalTx(txLockSessionId));

            // and
            TransactionCommitProcess localCommitProcess = CreateFakeTransactionCommitProcess(anyTransactionId);

            // when
            stateMachine.InstallCommitProcess(localCommitProcess, lastCommittedIndex);

            // then
            assertEquals(lastCommittedIndex, _commandIndexTracker.AppliedCommandIndex);

            // when
            stateMachine.ApplyCommand(replicatedTransaction, updatedCommandIndex, result =>
            {
            });
            stateMachine.EnsuredApplied();

            // then
            assertEquals(updatedCommandIndex, _commandIndexTracker.AppliedCommandIndex);
        }
Exemple #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public long commit(final org.neo4j.kernel.impl.api.TransactionToApply tx, final org.neo4j.kernel.impl.transaction.tracing.CommitEvent commitEvent, org.neo4j.storageengine.api.TransactionApplicationMode mode) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        public override long Commit(TransactionToApply tx, CommitEvent commitEvent, TransactionApplicationMode mode)
        {
            TransactionRepresentationReplicatedTransaction transaction = ReplicatedTransaction.from(tx.TransactionRepresentation());
            Future <object> futureTxId;

            try
            {
                futureTxId = _replicator.replicate(transaction, true);
            }
            catch (ReplicationFailureException e)
            {
                throw new TransactionFailureException(ReplicationFailure, e);
            }

            try
            {
                return(( long )futureTxId.get());
            }
            catch (ExecutionException e)
            {
                if (e.InnerException is TransactionFailureException)
                {
                    throw ( TransactionFailureException )e.InnerException;
                }
                // TODO: Panic?
                throw new Exception(e);
            }
            catch (InterruptedException e)
            {
                // TODO Wait for the transaction to possibly finish within a user configurable time, before aborting.
                throw new TransactionFailureException("Interrupted while waiting for txId", e);
            }
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAcceptTransactionCommittedWithNoLockManager() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAcceptTransactionCommittedWithNoLockManager()
        {
            // given
            int  txLockSessionId      = Org.Neo4j.Kernel.impl.locking.Locks_Client_Fields.NO_LOCK_SESSION_ID;
            int  currentLockSessionId = 24;
            long txId = 42L;

            ReplicatedTransaction tx = ReplicatedTransaction.from(PhysicalTx(txLockSessionId));

            TransactionCommitProcess localCommitProcess = CreateFakeTransactionCommitProcess(txId);

            ReplicatedTransactionStateMachine stateMachine = new ReplicatedTransactionStateMachine(_commandIndexTracker, LockState(currentLockSessionId), _batchSize, _logProvider, Org.Neo4j.Io.pagecache.tracing.cursor.PageCursorTracerSupplier_Fields.Null, EmptyVersionContextSupplier.EMPTY);

            stateMachine.InstallCommitProcess(localCommitProcess, -1L);

            AtomicBoolean called = new AtomicBoolean();

            // when
            stateMachine.ApplyCommand(tx, 0, result =>
            {
                // then
                called.set(true);
                try
                {
                    assertEquals(txId, ( long )result.consume());
                }
                catch (Exception e)
                {
                    throw new Exception(e);
                }
            });
            stateMachine.EnsuredApplied();

            assertTrue(called.get());
        }
Exemple #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static ReplicatedTransaction unmarshal(org.neo4j.storageengine.api.ReadableChannel channel) throws java.io.IOException
        public static ReplicatedTransaction Unmarshal(ReadableChannel channel)
        {
            int txBytesLength = channel.Int;

            sbyte[] txBytes = new sbyte[txBytesLength];
            channel.Get(txBytes, txBytesLength);
            return(ReplicatedTransaction.from(txBytes));
        }
Exemple #5
0
        public static ReplicatedTransaction Decode(ByteBuf byteBuf)
        {
            int length = byteBuf.readableBytes();

            sbyte[] bytes = new sbyte[length];
            byteBuf.readBytes(bytes);
            return(ReplicatedTransaction.from(bytes));
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldMarshalTransactionReferenceWithMissingHeader() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldMarshalTransactionReferenceWithMissingHeader()
        {
            ByteBuf buffer = Unpooled.buffer();
            PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation(Collections.emptyList());

            TransactionRepresentationReplicatedTransaction replicatedTx = ReplicatedTransaction.from(representation);

            AssertMarshalingEquality(buffer, replicatedTx);
        }
Exemple #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Parameterized.Parameters(name = "{0}") public static org.neo4j.causalclustering.core.replication.ReplicatedContent[] data()
        public static ReplicatedContent[] Data()
        {
            return(new ReplicatedContent[]
            {
                new DummyRequest(new sbyte[] { 1, 2, 3 }),
                ReplicatedTransaction.from(new sbyte[16 * 1024]),
                new MemberIdSet(new HashSet <MemberId>()
                {
                    { add(new MemberId(System.Guid.randomUUID())); }
                }),
Exemple #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowExceptionIfNotAllResourcesAreUsed()
        public virtual void ShouldThrowExceptionIfNotAllResourcesAreUsed()
        {
            try
            {
                RaftMessageComposer raftMessageComposer = new RaftMessageComposer(Clock.systemUTC());

                ReplicatedTransaction replicatedTransaction = ReplicatedTransaction.from(new sbyte[0]);
                raftMessageComposer.Decode(null, replicatedTransaction, null);
                IList <object> @out = new List <object>();
                raftMessageComposer.Decode(null, MessageCreator((a, b) => DummyRequest()), @out);
            }
            catch (System.InvalidOperationException e)
            {
                assertThat(e.Message, containsString("was composed without using all resources in the pipeline. Pipeline still contains Replicated contents"));
                return;
            }
            fail();
        }
Exemple #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldMarshalToSameByteIfByteBufBackedOrNot() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldMarshalToSameByteIfByteBufBackedOrNot()
        {
            PhysicalTransactionRepresentation expectedTx = new PhysicalTransactionRepresentation(Collections.singleton(new Command.NodeCommand(new NodeRecord(1), new NodeRecord(2))));

            expectedTx.SetHeader(new sbyte[0], 1, 2, 3, 4, 5, 6);
            TransactionRepresentationReplicatedTransaction replicatedTransaction = ReplicatedTransaction.from(expectedTx);

            MemoryStream stream = new MemoryStream();
            ByteBuf      buffer = Buffers.buffer();
            OutputStreamWritableChannel outputStreamWritableChannel = new OutputStreamWritableChannel(stream);
            NetworkWritableChannel      networkWritableChannel      = new NetworkWritableChannel(buffer);

            replicatedTransaction.Marshal(outputStreamWritableChannel);
            replicatedTransaction.Marshal(networkWritableChannel);

            sbyte[] bufferArray = Arrays.copyOf(buffer.array(), buffer.writerIndex());

            Assertions.assertArrayEquals(bufferArray, stream.toByteArray());
        }
Exemple #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailFutureForTransactionCommittedUnderWrongLockSession()
        public virtual void ShouldFailFutureForTransactionCommittedUnderWrongLockSession()
        {
            // given
            int txLockSessionId      = 23;
            int currentLockSessionId = 24;

            ReplicatedTransaction tx = ReplicatedTransaction.from(PhysicalTx(txLockSessionId));

            TransactionCommitProcess localCommitProcess = mock(typeof(TransactionCommitProcess));

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ReplicatedTransactionStateMachine stateMachine = new ReplicatedTransactionStateMachine(commandIndexTracker, lockState(currentLockSessionId), batchSize, logProvider, org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier_Fields.NULL, org.neo4j.io.pagecache.tracing.cursor.context.EmptyVersionContextSupplier.EMPTY);
            ReplicatedTransactionStateMachine stateMachine = new ReplicatedTransactionStateMachine(_commandIndexTracker, LockState(currentLockSessionId), _batchSize, _logProvider, Org.Neo4j.Io.pagecache.tracing.cursor.PageCursorTracerSupplier_Fields.Null, EmptyVersionContextSupplier.EMPTY);

            stateMachine.InstallCommitProcess(localCommitProcess, -1L);

            AtomicBoolean called = new AtomicBoolean();

            // when
            stateMachine.ApplyCommand(tx, 0, result =>
            {
                // then
                called.set(true);
                try
                {
                    result.consume();
                    fail("should have thrown");
                }
                catch (TransactionFailureException tfe)
                {
                    assertEquals(Status.Transaction.LockSessionExpired, tfe.status());
                }
                catch (Exception e)
                {
                    throw new Exception(e);
                }
            });
            stateMachine.EnsuredApplied();

            assertTrue(called.get());
        }
Exemple #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException
        public static void Main(string[] args)
        {
            Args arg = Args.parse(args);

            string from = arg.Get("from");

            Console.WriteLine("From is " + from);
            string to = arg.Get("to");

            Console.WriteLine("to is " + to);

            File logDirectory = new File(from);

            Console.WriteLine("logDirectory = " + logDirectory);
            Config config = Config.defaults(stringMap());

            using (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction())
            {
                LogProvider            logProvider     = Instance;
                CoreLogPruningStrategy pruningStrategy = (new CoreLogPruningStrategyFactory(config.Get(raft_log_pruning_strategy), logProvider)).newInstance();
                SegmentedRaftLog       log             = new SegmentedRaftLog(fileSystem, logDirectory, config.Get(raft_log_rotation_size), CoreReplicatedContentMarshal.marshaller(), logProvider, config.Get(raft_log_reader_pool_size), Clocks.systemClock(), new ThreadPoolJobScheduler(), pruningStrategy);

                long totalCommittedEntries = log.AppendIndex();                         // Not really, but we need to have a way to pass in the commit index
                for (int i = 0; i <= totalCommittedEntries; i++)
                {
                    ReplicatedContent content = readLogEntry(log, i).content();
                    if (content is ReplicatedTransaction)
                    {
                        ReplicatedTransaction tx = ( ReplicatedTransaction )content;
                        ReplicatedTransactionFactory.extractTransactionRepresentation(tx, new sbyte[0]).accept(element =>
                        {
                            Console.WriteLine(element);
                            return(false);
                        });
                    }
                }
            }
        }
Exemple #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCommitTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCommitTransaction()
        {
            // given
            int lockSessionId = 23;

            ReplicatedTransaction tx = ReplicatedTransaction.from(PhysicalTx(lockSessionId));

            TransactionCommitProcess localCommitProcess = mock(typeof(TransactionCommitProcess));
            PageCursorTracer         cursorTracer       = mock(typeof(PageCursorTracer));

            ReplicatedTransactionStateMachine stateMachine = new ReplicatedTransactionStateMachine(_commandIndexTracker, LockState(lockSessionId), _batchSize, _logProvider, () => cursorTracer, EmptyVersionContextSupplier.EMPTY);

            stateMachine.InstallCommitProcess(localCommitProcess, -1L);

            // when
            stateMachine.ApplyCommand(tx, 0, r =>
            {
            });
            stateMachine.EnsuredApplied();

            // then
            verify(localCommitProcess, times(1)).commit(any(typeof(TransactionToApply)), any(typeof(CommitEvent)), any(typeof(TransactionApplicationMode)));
            verify(cursorTracer, times(1)).reportEvents();
        }
Exemple #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void handle(org.neo4j.causalclustering.core.state.machines.tx.ReplicatedTransaction replicatedTransaction) throws java.io.IOException
            public override void Handle(ReplicatedTransaction replicatedTransaction)
            {
                WritableChannel.put(TX_CONTENT_TYPE);
                replicatedTransaction.Marshal(WritableChannel);
            }
Exemple #14
0
 public override void Handle(ReplicatedTransaction replicatedTransaction)
 {
     Output.Add(ChunkedReplicatedContent.Chunked(TX_CONTENT_TYPE, new MaxTotalSize(replicatedTransaction.Encode())));
 }
Exemple #15
0
 public override void Dispatch(ReplicatedTransaction transaction, long commandIndex, System.Action <Result> callback)
 {
     outerInstance.replicatedTxStateMachine.ApplyCommand(transaction, commandIndex, callback);
 }
Exemple #16
0
 public static TransactionRepresentation ExtractTransactionRepresentation(ReplicatedTransaction transactionCommand, sbyte[] extraHeader)
 {
     return(transactionCommand.Extract(new TransactionRepresentationReader(extraHeader)));
 }
Exemple #17
0
 private ReplicatedTransaction Tx(sbyte dataValue)
 {
     sbyte[] dataArray = new sbyte[30];
     Arrays.fill(dataArray, dataValue);
     return(ReplicatedTransaction.from(dataArray));
 }