Ejemplo n.º 1
0
        private KernelTransactionImplementation CreateTransaction()
        {
            KernelTransactionImplementation transaction = mock(typeof(KernelTransactionImplementation));

            try
            {
                TransactionHeaderInformation        headerInformation        = new TransactionHeaderInformation(-1, -1, new sbyte[0]);
                TransactionHeaderInformationFactory headerInformationFactory = mock(typeof(TransactionHeaderInformationFactory));
                when(headerInformationFactory.Create()).thenReturn(headerInformation);
                StorageEngine storageEngine = mock(typeof(StorageEngine));
                StorageReader storageReader = mock(typeof(StorageReader));
                when(storageEngine.NewReader()).thenReturn(storageReader);

                SimpleStatementLocks locks = new SimpleStatementLocks(mock(typeof(Org.Neo4j.Kernel.impl.locking.Locks_Client)));
                when(transaction.StatementLocks()).thenReturn(locks);
                when(transaction.TokenRead()).thenReturn(_tokenRead);
                when(transaction.SchemaRead()).thenReturn(_schemaRead);
                when(transaction.SchemaWrite()).thenReturn(_schemaWrite);
                TransactionState transactionState = mock(typeof(TransactionState));
                when(transaction.TxState()).thenReturn(transactionState);
                when(transaction.IndexUniqueCreate(any(typeof(SchemaDescriptor)), any(typeof(string)))).thenAnswer(i => IndexDescriptorFactory.uniqueForSchema(i.getArgument(0)));
            }
            catch (InvalidTransactionTypeKernelException)
            {
                fail("Expected write transaction");
            }
            catch (SchemaKernelException e)
            {
                throw new Exception(e);
            }
            return(transaction);
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") private org.neo4j.storageengine.api.StorageEngine mockedStorageEngine() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        private StorageEngine MockedStorageEngine()
        {
            StorageEngine storageEngine = mock(typeof(StorageEngine));

            doAnswer(invocation =>
            {
                ICollection <StorageCommand> target = invocation.getArgument(0);
                ReadableTransactionState txState    = invocation.getArgument(1);
                txState.accept(new AdapterAnonymousInnerClass(this, target));
                return(null);
            }).when(storageEngine).createCommands(anyCollection(), any(typeof(ReadableTransactionState)), any(typeof(StorageReader)), any(typeof(ResourceLocker)), anyLong(), any(typeof(TxStateVisitor.Decorator)));

            StorageReader readLayer = mock(typeof(StorageReader));

            when(storageEngine.NewReader()).thenReturn(readLayer);
            return(storageEngine);
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static KernelTransactions newKernelTransactions(boolean testKernelTransactions, TransactionCommitProcess commitProcess, org.neo4j.storageengine.api.StorageReader firstReader, org.neo4j.storageengine.api.StorageReader... otherReaders) throws Throwable
        private static KernelTransactions NewKernelTransactions(bool testKernelTransactions, TransactionCommitProcess commitProcess, StorageReader firstReader, params StorageReader[] otherReaders)
        {
            Locks locks = mock(typeof(Locks));

            Org.Neo4j.Kernel.impl.locking.Locks_Client client = mock(typeof(Org.Neo4j.Kernel.impl.locking.Locks_Client));
            when(locks.NewClient()).thenReturn(client);

            StorageEngine storageEngine = mock(typeof(StorageEngine));

            when(storageEngine.NewReader()).thenReturn(firstReader, otherReaders);
            doAnswer(invocation =>
            {
                ICollection <StorageCommand> argument = invocation.getArgument(0);
                argument.add(mock(typeof(StorageCommand)));
                return(null);
            }).when(storageEngine).createCommands(anyCollection(), any(typeof(ReadableTransactionState)), any(typeof(StorageReader)), any(typeof(ResourceLocker)), anyLong(), any(typeof(TxStateVisitor.Decorator)));

            return(NewKernelTransactions(locks, storageEngine, commitProcess, testKernelTransactions));
        }
Ejemplo n.º 4
0
        private sbyte[] CreateCommands(string tokenName)
        {
            StorageEngine storageEngine           = _storageEngineSupplier.get();
            ICollection <StorageCommand> commands = new List <StorageCommand>();
            TransactionState             txState  = new TxState();
            int tokenId = Math.toIntExact(_idGeneratorFactory.get(_tokenIdType).nextId());

            _tokenCreator.createToken(txState, tokenName, tokenId);
            try
            {
                using (StorageReader statement = storageEngine.NewReader())
                {
                    storageEngine.CreateCommands(commands, txState, statement, [email protected]_Fields.None, long.MaxValue, NO_DECORATION);
                }
            }
            catch (Exception e) when(e is CreateConstraintFailureException || e is TransactionFailureException || e is ConstraintValidationException)
            {
                throw new Exception("Unable to create token '" + tokenName + "'", e);
            }

            return(ReplicatedTokenRequestSerializer.CommandBytes(commands));
        }