Ejemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReuseExistingOrphanedConstraintIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReuseExistingOrphanedConstraintIndex()
        {
            // given
            IndexingService indexingService = mock(typeof(IndexingService));
            StubKernel      kernel          = new StubKernel(this);

            long orphanedConstraintIndexId = 111;

            when(_schemaRead.indexGetCommittedId(_indexReference)).thenReturn(orphanedConstraintIndexId);
            IndexProxy indexProxy = mock(typeof(IndexProxy));

            when(indexingService.GetIndexProxy(orphanedConstraintIndexId)).thenReturn(indexProxy);
            NodePropertyAccessor nodePropertyAccessor = mock(typeof(NodePropertyAccessor));

            when(_schemaRead.index(_descriptor)).thenReturn(_indexReference);
            when(_schemaRead.indexGetOwningUniquenessConstraintId(_indexReference)).thenReturn(null);                     // which means it has no owner
            ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider);

            // when
            KernelTransactionImplementation transaction = CreateTransaction();
            long indexId = creator.CreateUniquenessConstraintIndex(transaction, _descriptor, DefaultProvider);

            // then
            assertEquals(orphanedConstraintIndexId, indexId);
            assertEquals("There should have been no need to acquire a statement to create the constraint index", 0, kernel.Transactions.Count);
            verify(_schemaRead).indexGetCommittedId(_indexReference);
            verify(_schemaRead).index(_descriptor);
            verify(_schemaRead).indexGetOwningUniquenessConstraintId(_indexReference);
            verifyNoMoreInteractions(_schemaRead);
            verify(indexProxy).awaitStoreScanCompleted(anyLong(), any());
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateConstraintIndexForSpecifiedProvider() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCreateConstraintIndexForSpecifiedProvider()
        {
            // given
            IndexingService indexingService = mock(typeof(IndexingService));
            StubKernel      kernel          = new StubKernel(this);

            when(_schemaRead.indexGetCommittedId(_indexReference)).thenReturn(INDEX_ID);
            IndexProxy indexProxy = mock(typeof(IndexProxy));

            when(indexingService.GetIndexProxy(INDEX_ID)).thenReturn(indexProxy);
            when(indexingService.getIndexProxy(_descriptor)).thenReturn(indexProxy);
            NodePropertyAccessor    nodePropertyAccessor = mock(typeof(NodePropertyAccessor));
            ConstraintIndexCreator  creator            = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider);
            IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("Groovy", "1.2");

            // when
            KernelTransactionImplementation transaction = CreateTransaction();

            creator.CreateUniquenessConstraintIndex(transaction, _descriptor, providerDescriptor.Name());

            // then
            assertEquals(1, kernel.Transactions.Count);
            KernelTransactionImplementation transactionInstance = kernel.Transactions[0];

            verify(transactionInstance).indexUniqueCreate(eq(_descriptor), eq(providerDescriptor.Name()));
            verify(_schemaRead).index(_descriptor);
            verify(_schemaRead).indexGetCommittedId(any());
            verifyNoMoreInteractions(_schemaRead);
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void failForceIndexesWhenOneOfTheIndexesIsBroken() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void FailForceIndexesWhenOneOfTheIndexesIsBroken()
        {
            string constraintLabelPrefix    = "ConstraintLabel";
            string constraintPropertyPrefix = "ConstraintProperty";
            string indexLabelPrefix         = "Label";
            string indexPropertyPrefix      = "Property";

            for (int i = 0; i < 10; i++)
            {
                using (Transaction transaction = _database.beginTx())
                {
                    _database.schema().constraintFor(Label.label(constraintLabelPrefix + i)).assertPropertyIsUnique(constraintPropertyPrefix + i).create();
                    _database.schema().indexFor(Label.label(indexLabelPrefix + i)).on(indexPropertyPrefix + i).create();
                    transaction.Success();
                }
            }

            using (Transaction ignored = _database.beginTx())
            {
                _database.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
            }

            IndexingService indexingService = GetIndexingService(_database);

            int indexLabel7    = GetLabelId(indexLabelPrefix + 7);
            int indexProperty7 = GetPropertyKeyId(indexPropertyPrefix + 7);

            IndexProxy index = indexingService.GetIndexProxy(TestIndexDescriptorFactory.forLabel(indexLabel7, indexProperty7).schema());

            index.Drop();

            ExpectedException.expect(typeof(UnderlyingStorageException));
            ExpectedException.expectMessage("Unable to force");
            indexingService.ForceAll(Org.Neo4j.Io.pagecache.IOLimiter_Fields.Unlimited);
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustDiscoverRelationshipInStoreMissingFromIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MustDiscoverRelationshipInStoreMissingFromIndex()
        {
            GraphDatabaseService db = CreateDatabase();

            using (Transaction tx = Db.beginTx())
            {
                Db.execute(format(RELATIONSHIP_CREATE, "rels", array("REL"), array("prop"))).close();
                tx.Success();
            }
            StoreIndexDescriptor indexDescriptor;
            long relId;

            using (Transaction tx = Db.beginTx())
            {
                Db.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
                indexDescriptor = GetIndexDescriptor(first(Db.schema().Indexes));
                Node         node = Db.createNode();
                Relationship rel  = node.CreateRelationshipTo(node, RelationshipType.withName("REL"));
                rel.SetProperty("prop", "value");
                relId = rel.Id;
                tx.Success();
            }
            IndexingService indexes    = GetIndexingService(db);
            IndexProxy      indexProxy = indexes.GetIndexProxy(indexDescriptor.Schema());

            using (IndexUpdater updater = indexProxy.NewUpdater(IndexUpdateMode.ONLINE))
            {
                updater.Process(IndexEntryUpdate.remove(relId, indexDescriptor, Values.stringValue("value")));
            }

            Db.shutdown();

            ConsistencyCheckService.Result result = CheckConsistency();
            assertFalse(result.Successful);
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDropIndexIfPopulationFails() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDropIndexIfPopulationFails()
        {
            // given

            StubKernel kernel = new StubKernel(this);

            IndexingService indexingService = mock(typeof(IndexingService));
            IndexProxy      indexProxy      = mock(typeof(IndexProxy));

            when(indexingService.GetIndexProxy(INDEX_ID)).thenReturn(indexProxy);
            when(indexingService.getIndexProxy(_descriptor)).thenReturn(indexProxy);
            when(indexProxy.Descriptor).thenReturn(_index.withId(INDEX_ID).withoutCapabilities());

            IndexEntryConflictException cause = new IndexEntryConflictException(2, 1, Values.of("a"));

            doThrow(new IndexPopulationFailedKernelException("some index", cause)).when(indexProxy).awaitStoreScanCompleted(anyLong(), any());
            NodePropertyAccessor nodePropertyAccessor = mock(typeof(NodePropertyAccessor));

            when(_schemaRead.index(any(typeof(SchemaDescriptor)))).thenReturn(IndexReference.NO_INDEX).thenReturn(_indexReference);                           // then after it failed claim it does exist
            ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider);

            // when
            KernelTransactionImplementation transaction = CreateTransaction();

            try
            {
                creator.CreateUniquenessConstraintIndex(transaction, _descriptor, DefaultProvider);

                fail("expected exception");
            }
            // then
            catch (UniquePropertyValueValidationException e)
            {
                assertEquals("Existing data does not satisfy CONSTRAINT ON ( label[123]:label[123] ) " + "ASSERT label[123].property[456] IS UNIQUE: Both node 2 and node 1 share the property value ( String(\"a\") )", e.Message);
            }
            assertEquals(2, kernel.Transactions.Count);
            KernelTransactionImplementation tx1 = kernel.Transactions[0];
            SchemaDescriptor newIndex           = _index.schema();

            verify(tx1).indexUniqueCreate(eq(newIndex), eq(DefaultProvider));
            verify(_schemaRead).indexGetCommittedId(_indexReference);
            verify(_schemaRead, times(2)).index(_descriptor);
            verifyNoMoreInteractions(_schemaRead);
            TransactionState tx2 = kernel.Transactions[1].txState();

            verify(tx2).indexDoDrop(_index);
            verifyNoMoreInteractions(tx2);
        }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void logMessagesAboutConstraintCreation() throws org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException, org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException, org.neo4j.internal.kernel.api.exceptions.TransactionFailureException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LogMessagesAboutConstraintCreation()
        {
            StubKernel      kernel          = new StubKernel(this);
            IndexProxy      indexProxy      = mock(typeof(IndexProxy));
            IndexingService indexingService = mock(typeof(IndexingService));

            when(indexingService.GetIndexProxy(INDEX_ID)).thenReturn(indexProxy);
            when(indexingService.getIndexProxy(_descriptor)).thenReturn(indexProxy);
            when(indexProxy.Descriptor).thenReturn(_index.withId(INDEX_ID).withoutCapabilities());
            NodePropertyAccessor            propertyAccessor = mock(typeof(NodePropertyAccessor));
            ConstraintIndexCreator          creator          = new ConstraintIndexCreator(() => kernel, indexingService, propertyAccessor, _logProvider);
            KernelTransactionImplementation transaction      = CreateTransaction();

            creator.CreateUniquenessConstraintIndex(transaction, _descriptor, "indexProviderByName-1.0");

            _logProvider.rawMessageMatcher().assertContains("Starting constraint creation: %s.");
            _logProvider.rawMessageMatcher().assertContains("Constraint %s populated, starting verification.");
            _logProvider.rawMessageMatcher().assertContains("Constraint %s verified.");
        }
Ejemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailOnExistingOwnedConstraintIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFailOnExistingOwnedConstraintIndex()
        {
            // given
            IndexingService indexingService = mock(typeof(IndexingService));
            StubKernel      kernel          = new StubKernel(this);

            long constraintIndexId      = 111;
            long constraintIndexOwnerId = 222;

            when(_schemaRead.indexGetCommittedId(_indexReference)).thenReturn(constraintIndexId);
            IndexProxy indexProxy = mock(typeof(IndexProxy));

            when(indexingService.GetIndexProxy(constraintIndexId)).thenReturn(indexProxy);
            NodePropertyAccessor nodePropertyAccessor = mock(typeof(NodePropertyAccessor));

            when(_schemaRead.index(_descriptor)).thenReturn(_indexReference);
            when(_schemaRead.indexGetOwningUniquenessConstraintId(_indexReference)).thenReturn(constraintIndexOwnerId);                     // which means there's an owner
            when(_tokenRead.nodeLabelName(LABEL_ID)).thenReturn("MyLabel");
            when(_tokenRead.propertyKeyName(PROPERTY_KEY_ID)).thenReturn("MyKey");
            ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider);

            // when
            try
            {
                KernelTransactionImplementation transaction = CreateTransaction();
                creator.CreateUniquenessConstraintIndex(transaction, _descriptor, DefaultProvider);
                fail("Should've failed");
            }
            catch (AlreadyConstrainedException)
            {
                // THEN good
            }

            // then
            assertEquals("There should have been no need to acquire a statement to create the constraint index", 0, kernel.Transactions.Count);
            verify(_schemaRead).index(_descriptor);
            verify(_schemaRead).indexGetOwningUniquenessConstraintId(_indexReference);
            verifyNoMoreInteractions(_schemaRead);
        }
Ejemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateIndexInAnotherTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCreateIndexInAnotherTransaction()
        {
            // given
            StubKernel      kernel          = new StubKernel(this);
            IndexProxy      indexProxy      = mock(typeof(IndexProxy));
            IndexingService indexingService = mock(typeof(IndexingService));

            when(indexingService.GetIndexProxy(INDEX_ID)).thenReturn(indexProxy);
            when(indexingService.getIndexProxy(_descriptor)).thenReturn(indexProxy);
            when(indexProxy.Descriptor).thenReturn(_index.withId(INDEX_ID).withoutCapabilities());
            NodePropertyAccessor   nodePropertyAccessor = mock(typeof(NodePropertyAccessor));
            ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider);

            // when
            long indexId = creator.CreateUniquenessConstraintIndex(CreateTransaction(), _descriptor, DefaultProvider);

            // then
            assertEquals(INDEX_ID, indexId);
            verify(_schemaRead).indexGetCommittedId(_indexReference);
            verify(_schemaRead).index(_descriptor);
            verifyNoMoreInteractions(_schemaRead);
            verify(indexProxy).awaitStoreScanCompleted(anyLong(), any());
        }