Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void should_list_constraints()
        public virtual void ShouldListConstraints()
        {
            // GIVEN
            SchemaCache cache = NewSchemaCache();

            // WHEN
            cache.AddSchemaRule(UniquenessConstraintRule(0L, 1, 2, 133L));
            cache.AddSchemaRule(UniquenessConstraintRule(1L, 3, 4, 133L));
            cache.AddSchemaRule(RelPropertyExistenceConstraintRule(2L, 5, 6));
            cache.AddSchemaRule(NodePropertyExistenceConstraintRule(3L, 7, 8));

            // THEN
            ConstraintDescriptor unique1    = uniqueForLabel(1, 2);
            ConstraintDescriptor unique2    = uniqueForLabel(3, 4);
            ConstraintDescriptor existsRel  = ConstraintDescriptorFactory.existsForRelType(5, 6);
            ConstraintDescriptor existsNode = ConstraintDescriptorFactory.existsForLabel(7, 8);

            assertEquals(asSet(unique1, unique2, existsRel, existsNode), asSet(cache.Constraints()));

            assertEquals(asSet(unique1), asSet(cache.ConstraintsForLabel(1)));

            assertEquals(asSet(unique1), asSet(cache.ConstraintsForSchema(unique1.Schema())));

            assertEquals(asSet(), asSet(cache.ConstraintsForSchema(forLabel(1, 3))));

            assertEquals(asSet(existsRel), asSet(cache.ConstraintsForRelationshipType(5)));
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void concurrentSchemaRuleRemove() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ConcurrentSchemaRuleRemove()
        {
            SchemaCache cache       = NewSchemaCache();
            int         indexNumber = 20;

            for (int i = 0; i < indexNumber; i++)
            {
                cache.AddSchemaRule(NewIndexRule(i, i, i));
            }
            Race race = new Race();
            int  numberOfDeletions = 10;

            for (int i = 0; i < numberOfDeletions; i++)
            {
                int indexId = i;
                race.AddContestant(() => cache.removeSchemaRule(indexId));
            }
            race.Go();

            assertEquals(indexNumber - numberOfDeletions, Iterables.count(cache.IndexDescriptors()));
            for (int labelId = numberOfDeletions; labelId < indexNumber; labelId++)
            {
                assertEquals(1, Iterators.count(cache.IndexDescriptorsForLabel(labelId)));
            }
            for (int propertyId = numberOfDeletions; propertyId < indexNumber; propertyId++)
            {
                assertEquals(1, Iterators.count(cache.IndexesByProperty(propertyId)));
            }
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void schemaCacheSnapshotsShouldBeReadOnly()
        public virtual void SchemaCacheSnapshotsShouldBeReadOnly()
        {
            // Given
            SchemaCache cache = NewSchemaCache();

            cache.AddSchemaRule(NewIndexRule(1L, 1, 2));
            cache.AddSchemaRule(NewIndexRule(2L, 2, 3));

            SchemaCache snapshot = cache.Snapshot();

            cache.AddSchemaRule(NewIndexRule(3L, 1, 2));

            // When
            ISet <CapableIndexDescriptor> indexes = asSet(snapshot.IndexDescriptorsForLabel(1));

            // Then
            ISet <StoreIndexDescriptor> expected = asSet(NewIndexRule(1L, 1, 2));

            assertEquals(expected, indexes);

            try
            {
                snapshot.AddSchemaRule(NewIndexRule(3L, 1, 2));
                fail("SchemaCache snapshots should not permit mutation.");
            }
            catch (System.InvalidOperationException)
            {
                // Good.
            }
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void should_construct_schema_cache()
        public virtual void ShouldConstructSchemaCache()
        {
            // GIVEN
            ICollection <SchemaRule> rules = asList(_hans, _witch, _gretel, _robot);
            SchemaCache cache = new SchemaCache(new ConstraintSemantics(), rules, IndexProviderMap.EMPTY);

            // THEN
            assertEquals(asSet(_hans, _gretel), Iterables.asSet(cache.IndexDescriptors()));
            assertEquals(asSet(_witch, _robot), Iterables.asSet(cache.ConstraintRules()));
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnNullWhenNoIndexExists()
        public virtual void ShouldReturnNullWhenNoIndexExists()
        {
            // Given
            SchemaCache schemaCache = NewSchemaCache();

            // When
            IndexDescriptor schemaIndexDescriptor = schemaCache.IndexDescriptor(forLabel(1, 1));

            // Then
            assertNull(schemaIndexDescriptor);
        }
Exemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void adding_constraints_should_be_idempotent()
        public virtual void AddingConstraintsShouldBeIdempotent()
        {
            // given
            SchemaCache cache = NewSchemaCache();

            cache.AddSchemaRule(UniquenessConstraintRule(0L, 1, 2, 133L));

            // when
            cache.AddSchemaRule(UniquenessConstraintRule(0L, 1, 2, 133L));

            // then
            assertEquals(asList(uniqueForLabel(1, 2)), Iterators.asList(cache.Constraints()));
        }
Exemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void addSchemaRules()
        public virtual void AddSchemaRules()
        {
            // GIVEN
            SchemaCache cache = NewSchemaCache();

            // WHEN
            cache.AddSchemaRule(_hans);
            cache.AddSchemaRule(_gretel);
            cache.AddSchemaRule(_witch);
            cache.AddSchemaRule(_robot);

            // THEN
            assertEquals(asSet(_hans, _gretel), Iterables.asSet(cache.IndexDescriptors()));
            assertEquals(asSet(_witch, _robot), Iterables.asSet(cache.ConstraintRules()));
        }
Exemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldResolveIndexDescriptor()
        public virtual void ShouldResolveIndexDescriptor()
        {
            // Given
            SchemaCache cache = NewSchemaCache();

            cache.AddSchemaRule(NewIndexRule(1L, 1, 2));
            cache.AddSchemaRule(NewIndexRule(2L, 1, 3));
            cache.AddSchemaRule(NewIndexRule(3L, 2, 2));

            // When
            LabelSchemaDescriptor schema     = forLabel(1, 3);
            IndexDescriptor       descriptor = cache.IndexDescriptor(schema);

            // Then
            assertThat(descriptor.Schema(), equalTo(schema));
        }
Exemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void addRemoveIndexes()
        public virtual void AddRemoveIndexes()
        {
            ICollection <SchemaRule> rules = asList(_hans, _witch, _gretel, _robot);
            SchemaCache cache = new SchemaCache(new ConstraintSemantics(), rules, IndexProviderMap.EMPTY);

            StoreIndexDescriptor rule1 = NewIndexRule(10, 11, 12);
            StoreIndexDescriptor rule2 = NewIndexRule(13, 14, 15);

            cache.AddSchemaRule(rule1);
            cache.AddSchemaRule(rule2);

            cache.RemoveSchemaRule(_hans.Id);
            cache.RemoveSchemaRule(_witch.Id);

            assertEquals(asSet(_gretel, rule1, rule2), Iterables.asSet(cache.IndexDescriptors()));
            assertEquals(asSet(_robot), Iterables.asSet(cache.ConstraintRules()));
        }
Exemplo n.º 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldListConstraintsForSchema()
        public virtual void ShouldListConstraintsForSchema()
        {
            // Given
            ConstraintRule rule1 = UniquenessConstraintRule(0, 1, 1, 0);
            ConstraintRule rule2 = UniquenessConstraintRule(1, 2, 1, 0);
            ConstraintRule rule3 = NodePropertyExistenceConstraintRule(2, 1, 2);

            SchemaCache cache = NewSchemaCache();

            cache.AddSchemaRule(rule1);
            cache.AddSchemaRule(rule2);
            cache.AddSchemaRule(rule3);

            // When
            ISet <ConstraintDescriptor> listed = asSet(cache.ConstraintsForSchema(rule3.Schema()));

            // Then
            assertEquals(singleton(rule3.ConstraintDescriptor), listed);
        }
Exemplo n.º 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void removeSchemaWithRepeatedRelType()
        public virtual void RemoveSchemaWithRepeatedRelType()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final SchemaCache cache = newSchemaCache();
            SchemaCache cache = NewSchemaCache();

            const int id = 1;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int[] repeatedRelTypes = {0, 1, 0};
            int[] repeatedRelTypes = new int[] { 0, 1, 0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.api.schema.MultiTokenSchemaDescriptor schema = org.neo4j.kernel.api.schema.SchemaDescriptorFactory.multiToken(repeatedRelTypes, org.neo4j.storageengine.api.EntityType.RELATIONSHIP, 1);
            MultiTokenSchemaDescriptor schema = SchemaDescriptorFactory.multiToken(repeatedRelTypes, EntityType.RELATIONSHIP, 1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.storageengine.api.schema.StoreIndexDescriptor storeIndexDescriptor = org.neo4j.storageengine.api.schema.IndexDescriptorFactory.forSchema(schema).withId(id);
            StoreIndexDescriptor storeIndexDescriptor = IndexDescriptorFactory.forSchema(schema).withId(id);

            cache.AddSchemaRule(storeIndexDescriptor);
            cache.RemoveSchemaRule(id);
        }
Exemplo n.º 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldListConstraintsForRelationshipType()
        public virtual void ShouldListConstraintsForRelationshipType()
        {
            // Given
            ConstraintRule rule1 = RelPropertyExistenceConstraintRule(0, 1, 1);
            ConstraintRule rule2 = RelPropertyExistenceConstraintRule(0, 2, 1);
            ConstraintRule rule3 = RelPropertyExistenceConstraintRule(0, 1, 2);

            SchemaCache cache = NewSchemaCache();

            cache.AddSchemaRule(rule1);
            cache.AddSchemaRule(rule2);
            cache.AddSchemaRule(rule3);

            // When
            ISet <ConstraintDescriptor> listed = asSet(cache.ConstraintsForRelationshipType(1));

            // Then
            ISet <ConstraintDescriptor> expected = asSet(rule1.ConstraintDescriptor, rule3.ConstraintDescriptor);

            assertEquals(expected, listed);
        }
Exemplo n.º 13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldListConstraintsForLabel()
        public virtual void ShouldListConstraintsForLabel()
        {
            // Given
            ConstraintRule rule1 = UniquenessConstraintRule(0, 1, 1, 0);
            ConstraintRule rule2 = UniquenessConstraintRule(1, 2, 1, 0);
            ConstraintRule rule3 = NodePropertyExistenceConstraintRule(2, 1, 2);

            SchemaCache cache = NewSchemaCache();

            cache.AddSchemaRule(rule1);
            cache.AddSchemaRule(rule2);
            cache.AddSchemaRule(rule3);

            // When
            ISet <ConstraintDescriptor> listed = asSet(cache.ConstraintsForLabel(1));

            // Then
            ISet <ConstraintDescriptor> expected = asSet(rule1.ConstraintDescriptor, rule3.ConstraintDescriptor);

            assertEquals(expected, listed);
        }
Exemplo n.º 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void should_remove_constraints()
        public virtual void ShouldRemoveConstraints()
        {
            // GIVEN
            SchemaCache cache = NewSchemaCache();

            cache.AddSchemaRule(UniquenessConstraintRule(0L, 1, 2, 133L));
            cache.AddSchemaRule(UniquenessConstraintRule(1L, 3, 4, 133L));

            // WHEN
            cache.RemoveSchemaRule(0L);

            // THEN
            ConstraintDescriptor dropped = uniqueForLabel(1, 1);
            ConstraintDescriptor unique  = uniqueForLabel(3, 4);

            assertEquals(asSet(unique), asSet(cache.Constraints()));

            assertEquals(asSet(), asSet(cache.ConstraintsForLabel(1)));

            assertEquals(asSet(), asSet(cache.ConstraintsForSchema(dropped.Schema())));
        }
Exemplo n.º 15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void concurrentSchemaRuleAdd() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ConcurrentSchemaRuleAdd()
        {
            SchemaCache cache       = NewSchemaCache();
            Race        race        = new Race();
            int         indexNumber = 10;

            for (int i = 0; i < indexNumber; i++)
            {
                int id = i;
                race.AddContestant(() => cache.addSchemaRule(NewIndexRule(id, id, id)));
            }
            race.Go();

            assertEquals(indexNumber, Iterables.count(cache.IndexDescriptors()));
            for (int labelId = 0; labelId < indexNumber; labelId++)
            {
                assertEquals(1, Iterators.count(cache.IndexDescriptorsForLabel(labelId)));
            }
            for (int propertyId = 0; propertyId < indexNumber; propertyId++)
            {
                assertEquals(1, Iterators.count(cache.IndexesByProperty(propertyId)));
            }
        }