Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void addingANodeWithPropertyShouldGetIndexed() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AddingANodeWithPropertyShouldGetIndexed()
        {
            // Given
            string indexProperty        = "indexProperty";
            GatheringIndexWriter writer = NewWriter();

            createIndex(_db, _myLabel, indexProperty);

            // When
            int    value1        = 12;
            string otherProperty = "otherProperty";
            int    otherValue    = 17;
            Node   node          = CreateNode(map(indexProperty, value1, otherProperty, otherValue), _myLabel);

            // Then, for now, this should trigger two NodePropertyUpdates
            using (Transaction tx = _db.beginTx())
            {
                KernelTransaction ktx       = _ctxSupplier.getKernelTransactionBoundToThisThread(true);
                TokenRead         tokenRead = ktx.TokenRead();
                int propertyKey1            = tokenRead.PropertyKey(indexProperty);
                int label = tokenRead.NodeLabel(_myLabel.name());
                LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(label, propertyKey1);
                assertThat(writer.UpdatesCommitted, equalTo(asSet(IndexEntryUpdate.add(node.Id, descriptor, Values.of(value1)))));
                tx.Success();
            }
            // We get two updates because we both add a label and a property to be indexed
            // in the same transaction, in the future, we should optimize this down to
            // one NodePropertyUpdate.
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private GatheringIndexWriter newWriter() throws java.io.IOException
        private GatheringIndexWriter NewWriter()
        {
            GatheringIndexWriter writer = new GatheringIndexWriter();

            when(_mockedIndexProvider.getPopulator(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)), any())).thenReturn(writer);
            when(_mockedIndexProvider.getOnlineAccessor(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)))).thenReturn(writer);
            return(writer);
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToRecoverAndUpdateOnlineIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToRecoverAndUpdateOnlineIndex()
        {
            // Given
            StartDb();

            IndexPopulator populator = mock(typeof(IndexPopulator));

            when(_mockedIndexProvider.getPopulator(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)), any())).thenReturn(populator);
            when(populator.SampleResult()).thenReturn(new IndexSample());
            IndexAccessor mockedAccessor = mock(typeof(IndexAccessor));

            when(mockedAccessor.NewUpdater(any(typeof(IndexUpdateMode)))).thenReturn(SwallowingIndexUpdater.INSTANCE);
            when(_mockedIndexProvider.getOnlineAccessor(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)))).thenReturn(mockedAccessor);
            CreateIndexAndAwaitPopulation(_myLabel);
            // rotate logs
            RotateLogsAndCheckPoint();
            // make updates
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Set<org.neo4j.kernel.api.index.IndexEntryUpdate<?>> expectedUpdates = createSomeBananas(myLabel);
            ISet <IndexEntryUpdate <object> > expectedUpdates = CreateSomeBananas(_myLabel);

            // And Given
            KillDb();
            when(_mockedIndexProvider.getInitialState(any(typeof(StoreIndexDescriptor)))).thenReturn(InternalIndexState.ONLINE);
            GatheringIndexWriter writer = new GatheringIndexWriter();

            when(_mockedIndexProvider.getOnlineAccessor(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)))).thenReturn(writer);

            // When
            StartDb();

            // Then
            assertThat(getIndexes(_db, _myLabel), inTx(_db, hasSize(1)));
            assertThat(getIndexes(_db, _myLabel), inTx(_db, haveState(_db, Org.Neo4j.Graphdb.schema.Schema_IndexState.Online)));
            verify(_mockedIndexProvider, times(1)).getPopulator(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)), any());
            int onlineAccessorInvocationCount = 2;               // once when we create the index, and once when we restart the db

            verify(_mockedIndexProvider, times(onlineAccessorInvocationCount)).getOnlineAccessor(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)));
            assertEquals(expectedUpdates, writer.BatchedUpdates);
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void addingALabelToPreExistingNodeShouldGetIndexed() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AddingALabelToPreExistingNodeShouldGetIndexed()
        {
            // GIVEN
            string indexProperty        = "indexProperty";
            GatheringIndexWriter writer = NewWriter();

            createIndex(_db, _myLabel, indexProperty);

            // WHEN
            string otherProperty = "otherProperty";
            int    value         = 12;
            int    otherValue    = 17;
            Node   node          = CreateNode(map(indexProperty, value, otherProperty, otherValue));

            // THEN
            assertThat(writer.UpdatesCommitted.Count, equalTo(0));

            // AND WHEN
            using (Transaction tx = _db.beginTx())
            {
                node.AddLabel(_myLabel);
                tx.Success();
            }

            // THEN
            using (Transaction tx = _db.beginTx())
            {
                KernelTransaction ktx       = _ctxSupplier.getKernelTransactionBoundToThisThread(true);
                TokenRead         tokenRead = ktx.TokenRead();
                int propertyKey1            = tokenRead.PropertyKey(indexProperty);
                int label = tokenRead.NodeLabel(_myLabel.name());
                LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(label, propertyKey1);
                assertThat(writer.UpdatesCommitted, equalTo(asSet(IndexEntryUpdate.add(node.Id, descriptor, Values.of(value)))));
                tx.Success();
            }
        }