//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProvideLabelScanStoreUpdatesSortedByNodeId() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProvideLabelScanStoreUpdatesSortedByNodeId()
        {
            // GIVEN
            IndexingService indexing = mock(typeof(IndexingService));

            when(indexing.ConvertToIndexUpdates(any(), eq(EntityType.NODE))).thenAnswer(o => Iterables.empty());
            LabelScanWriter writer = new OrderVerifyingLabelScanWriter(10, 15, 20);
            WorkSync <System.Func <LabelScanWriter>, LabelUpdateWork> labelScanSync    = spy(new WorkSync <System.Func <LabelScanWriter>, LabelUpdateWork>(SingletonProvider(writer)));
            WorkSync <IndexingUpdateService, IndexUpdatesWork>        indexUpdatesSync = new WorkSync <IndexingUpdateService, IndexUpdatesWork>(indexing);
            TransactionToApply tx            = mock(typeof(TransactionToApply));
            PropertyStore      propertyStore = mock(typeof(PropertyStore));

            using (IndexBatchTransactionApplier applier = new IndexBatchTransactionApplier(indexing, labelScanSync, indexUpdatesSync, mock(typeof(NodeStore)), mock(typeof(RelationshipStore)), propertyStore, new IndexActivator(indexing)))
            {
                using (TransactionApplier txApplier = applier.StartTx(tx))
                {
                    // WHEN
                    txApplier.VisitNodeCommand(Node(15));
                    txApplier.VisitNodeCommand(Node(20));
                    txApplier.VisitNodeCommand(Node(10));
                }
            }
            // THEN all assertions happen inside the LabelScanWriter#write and #close
            verify(labelScanSync).applyAsync(any());
        }
Exemple #2
0
        /// <summary>
        /// Get an applier suitable for the specified IndexCommand.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private TransactionApplier applier(org.neo4j.kernel.impl.index.IndexCommand command) throws java.io.IOException
        private TransactionApplier Applier(IndexCommand command)
        {
            // Have we got an applier for this index?
            string indexName = _defineCommand.getIndexName(command.IndexNameId);
            IDictionary <string, TransactionApplier> applierByIndex = ApplierByIndexMap(command);
            TransactionApplier applier = applierByIndex[indexName];

            if (applier == null)
            {
                // We don't. Have we got an applier for the provider of this index?
                IndexEntityType entityType          = IndexEntityType.byId(command.EntityType);
                IDictionary <string, string> config = _indexConfigStore.get(entityType.entityClass(), indexName);
                if (config == null)
                {
                    // This provider doesn't even exist, return an EMPTY handler, i.e. ignore these changes.
                    // Could be that the index provider is temporarily unavailable?
                    return(TransactionApplier_Fields.Empty);
                }
                string providerName = config[PROVIDER];
                applier = ApplierByProvider[providerName];
                if (applier == null)
                {
                    // We don't, so create the applier
                    applier = _applierLookup.newApplier(providerName, _mode.needsIdempotencyChecks());
                    applier.VisitIndexDefineCommand(_defineCommand);
                    ApplierByProvider[providerName] = applier;
                }

                // Also cache this applier for this index
                applierByIndex[indexName] = applier;
            }
            return(applier);
        }
Exemple #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void apply(org.neo4j.storageengine.api.CommandsToApply batch, org.neo4j.storageengine.api.TransactionApplicationMode mode) throws Exception
        public override void Apply(CommandsToApply batch, TransactionApplicationMode mode)
        {
            // Have these command appliers as separate try-with-resource to have better control over
            // point between closing this and the locks above
            try
            {
                using (IndexActivator indexActivator = new IndexActivator(_indexingService), LockGroup locks = new LockGroup(), BatchTransactionApplier batchApplier = Applier(mode, indexActivator))
                {
                    while (batch != null)
                    {
                        using (TransactionApplier txApplier = batchApplier.StartTx(batch, locks))
                        {
                            batch.Accept(txApplier);
                        }
                        batch = batch.Next();
                    }
                }
            }
            catch (Exception cause)
            {
                TransactionApplyKernelException kernelException = new TransactionApplyKernelException(cause, "Failed to apply transaction: %s", batch);
                _databaseHealth.panic(kernelException);
                throw kernelException;
            }
        }
Exemple #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDropIndexGivenDropSchemaRuleCommand() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDropIndexGivenDropSchemaRuleCommand()
        {
            // Given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.storageengine.api.schema.StoreIndexDescriptor indexRule = indexRule(1, 42, 42, INDEX_DESCRIPTOR);
            StoreIndexDescriptor indexRule = indexRule(1, 42, 42, _indexDescriptor);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final IndexBatchTransactionApplier applier = newIndexTransactionApplier();
            IndexBatchTransactionApplier applier = NewIndexTransactionApplier();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(singleton(createdDynamicRecord(1)), singleton(dynamicRecord(1, false)), indexRule);
            Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(singleton(CreatedDynamicRecord(1)), singleton(dynamicRecord(1, false)), indexRule);

            // When
            bool result;

            using (TransactionApplier txApplier = applier.StartTx(_transactionToApply))
            {
                result = txApplier.VisitSchemaRuleCommand(command);
            }

            // Then
            assertFalse(result);
            verify(_indexingService).dropIndex(indexRule);
        }
Exemple #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUpdateLabelStoreScanOnNodeCommands() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldUpdateLabelStoreScanOnNodeCommands()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final IndexBatchTransactionApplier applier = newIndexTransactionApplier();
            IndexBatchTransactionApplier applier = NewIndexTransactionApplier();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.store.record.NodeRecord before = new org.neo4j.kernel.impl.store.record.NodeRecord(11);
            NodeRecord before = new NodeRecord(11);

            before.SetLabelField(17, _emptyDynamicRecords);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.store.record.NodeRecord after = new org.neo4j.kernel.impl.store.record.NodeRecord(12);
            NodeRecord after = new NodeRecord(12);

            after.SetLabelField(18, _emptyDynamicRecords);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final Command.NodeCommand command = new Command.NodeCommand(before, after);
            Command.NodeCommand command = new Command.NodeCommand(before, after);

            LabelScanWriter labelScanWriter = mock(typeof(LabelScanWriter));

            when(_labelScanStore.get()).thenReturn(labelScanWriter);

            // when
            bool result;

            using (TransactionApplier txApplier = applier.StartTx(_transactionToApply))
            {
                result = txApplier.VisitNodeCommand(command);
            }
            // then
            assertFalse(result);
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp()
        public virtual void SetUp()
        {
            _txApplier1 = mock(typeof(TransactionApplier));
            _txApplier2 = mock(typeof(TransactionApplier));
            _txApplier3 = mock(typeof(TransactionApplier));

            _facade = new TransactionApplierFacade(_txApplier1, _txApplier2, _txApplier3);
        }
Exemple #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public TransactionApplier startTx(org.neo4j.storageengine.api.CommandsToApply transaction, org.neo4j.kernel.impl.locking.LockGroup lockGroup) throws java.io.IOException
        public override TransactionApplier StartTx(CommandsToApply transaction, LockGroup lockGroup)
        {
            TransactionApplier[] txAppliers = new TransactionApplier[_appliers.Length];
            for (int i = 0; i < _appliers.Length; i++)
            {
                txAppliers[i] = _appliers[i].startTx(transaction, lockGroup);
            }
            return(new TransactionApplierFacade(txAppliers));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRegisterIndexesToActivateIntoTheActivator() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRegisterIndexesToActivateIntoTheActivator()
        {
            // given
            IndexingService indexing = mock(typeof(IndexingService));
            LabelScanWriter writer   = new OrderVerifyingLabelScanWriter(10, 15, 20);
            WorkSync <System.Func <LabelScanWriter>, LabelUpdateWork> labelScanSync    = spy(new WorkSync <System.Func <LabelScanWriter>, LabelUpdateWork>(SingletonProvider(writer)));
            WorkSync <IndexingUpdateService, IndexUpdatesWork>        indexUpdatesSync = new WorkSync <IndexingUpdateService, IndexUpdatesWork>(indexing);
            PropertyStore      propertyStore  = mock(typeof(PropertyStore));
            TransactionToApply tx             = mock(typeof(TransactionToApply));
            IndexActivator     indexActivator = new IndexActivator(indexing);
            long indexId1      = 1;
            long indexId2      = 2;
            long indexId3      = 3;
            long constraintId1 = 10;
            long constraintId2 = 11;
            long constraintId3 = 12;
            IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("index-key", "v1");
            StoreIndexDescriptor    rule1 = uniqueForSchema(forLabel(1, 1), providerDescriptor).withIds(indexId1, constraintId1);
            StoreIndexDescriptor    rule2 = uniqueForSchema(forLabel(2, 1), providerDescriptor).withIds(indexId2, constraintId2);
            StoreIndexDescriptor    rule3 = uniqueForSchema(forLabel(3, 1), providerDescriptor).withIds(indexId3, constraintId3);

            using (IndexBatchTransactionApplier applier = new IndexBatchTransactionApplier(indexing, labelScanSync, indexUpdatesSync, mock(typeof(NodeStore)), mock(typeof(RelationshipStore)), propertyStore, indexActivator))
            {
                using (TransactionApplier txApplier = applier.StartTx(tx))
                {
                    // WHEN
                    // activate index 1
                    txApplier.VisitSchemaRuleCommand(new Command.SchemaRuleCommand(Collections.emptyList(), AsRecords(rule1, true), rule1));

                    // activate index 2
                    txApplier.VisitSchemaRuleCommand(new Command.SchemaRuleCommand(Collections.emptyList(), AsRecords(rule2, true), rule2));

                    // activate index 3
                    txApplier.VisitSchemaRuleCommand(new Command.SchemaRuleCommand(Collections.emptyList(), AsRecords(rule3, true), rule3));

                    // drop index 2
                    txApplier.VisitSchemaRuleCommand(new Command.SchemaRuleCommand(AsRecords(rule2, true), AsRecords(rule2, false), rule2));
                }
            }

            verify(indexing).dropIndex(rule2);
            indexActivator.Close();
            verify(indexing).activateIndex(indexId1);
            verify(indexing).activateIndex(indexId3);
            verifyNoMoreInteractions(indexing);
        }
Exemple #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SetUp()
        {
            _txApplier1 = mock(typeof(TransactionApplier));
            _applier1   = mock(typeof(BatchTransactionApplier));
            when(_applier1.startTx(any(typeof(TransactionToApply)))).thenReturn(_txApplier1);
            when(_applier1.startTx(any(typeof(TransactionToApply)), any(typeof(LockGroup)))).thenReturn(_txApplier1);

            _txApplier2 = mock(typeof(TransactionApplier));
            _applier2   = mock(typeof(BatchTransactionApplier));
            when(_applier2.startTx(any(typeof(TransactionToApply)))).thenReturn(_txApplier2);
            when(_applier2.startTx(any(typeof(TransactionToApply)), any(typeof(LockGroup)))).thenReturn(_txApplier2);

            _txApplier3 = mock(typeof(TransactionApplier));
            _applier3   = mock(typeof(BatchTransactionApplier));
            when(_applier3.startTx(any(typeof(TransactionToApply)))).thenReturn(_txApplier3);
            when(_applier3.startTx(any(typeof(TransactionToApply)), any(typeof(LockGroup)))).thenReturn(_txApplier3);

            _facade = new BatchTransactionApplierFacade(_applier1, _applier2, _applier3);
        }
Exemple #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotifyCacheAccessOnHowManyUpdatesOnCountsWeHadSoFar() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotifyCacheAccessOnHowManyUpdatesOnCountsWeHadSoFar()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.store.counts.CountsTracker tracker = mock(org.neo4j.kernel.impl.store.counts.CountsTracker.class);
            CountsTracker tracker = mock(typeof(CountsTracker));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final CountsAccessor_Updater updater = mock(CountsAccessor_Updater.class);
            CountsAccessor_Updater updater = mock(typeof(CountsAccessor_Updater));

            when(tracker.Apply(anyLong())).thenReturn(updater);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final CountsStoreBatchTransactionApplier applier = new CountsStoreBatchTransactionApplier(tracker, org.neo4j.storageengine.api.TransactionApplicationMode.INTERNAL);
            CountsStoreBatchTransactionApplier applier = new CountsStoreBatchTransactionApplier(tracker, TransactionApplicationMode.INTERNAL);

            // WHEN
            using (TransactionApplier txApplier = applier.StartTx(new TransactionToApply(null, 2L)))
            {
                txApplier.VisitNodeCountsCommand(new Command.NodeCountsCommand(StatementConstants.ANY_LABEL, 1));
            }

            // THEN
            verify(updater, times(1)).incrementNodeCount(StatementConstants.ANY_LABEL, 1);
        }