//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = IllegalArgumentException.class) public void constraintRuleNameMustNotBeTheEmptyString()
        public virtual void ConstraintRuleNameMustNotBeTheEmptyString()
        {
            //noinspection RedundantStringConstructorCall
            string name = "";

            ConstraintRule.constraintRule(RULE_ID, ConstraintDescriptorFactory.existsForLabel(LABEL_ID, PROPERTY_ID_1), name);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = IllegalArgumentException.class) public void nodeKeyConstraintRuleNameMustNotBeTheEmptyString()
        public virtual void NodeKeyConstraintRuleNameMustNotBeTheEmptyString()
        {
            //noinspection RedundantStringConstructorCall
            string name = "";

            ConstraintRule.ConstraintRuleConflict(RULE_ID, ConstraintDescriptorFactory.nodeKeyForLabel(LABEL_ID, PROPERTY_ID_1), RULE_ID_2, name);
        }
Пример #3
0
        // READ CONSTRAINT

//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static ConstraintRule readConstraintRule(long id, ByteBuffer source) throws org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException
        private static ConstraintRule ReadConstraintRule(long id, ByteBuffer source)
        {
            SchemaDescriptor schema;
            sbyte            constraintRuleType = source.get();
            string           name;

            switch (constraintRuleType)
            {
            case EXISTS_CONSTRAINT:
                schema = ReadSchema(source);
                name   = ReadRuleName(source).orElse(null);
                return(ConstraintRule.ConstraintRuleConflict(id, ConstraintDescriptorFactory.existsForSchema(schema), name));

            case UNIQUE_CONSTRAINT:
                long ownedUniqueIndex = source.Long;
                schema = ReadSchema(source);
                UniquenessConstraintDescriptor descriptor = ConstraintDescriptorFactory.uniqueForSchema(schema);
                name = ReadRuleName(source).orElse(null);
                return(ConstraintRule.ConstraintRuleConflict(id, descriptor, ownedUniqueIndex, name));

            case UNIQUE_EXISTS_CONSTRAINT:
                long ownedNodeKeyIndex = source.Long;
                schema = ReadSchema(source);
                NodeKeyConstraintDescriptor nodeKeyConstraintDescriptor = ConstraintDescriptorFactory.nodeKeyForSchema(schema);
                name = ReadRuleName(source).orElse(null);
                return(ConstraintRule.ConstraintRuleConflict(id, nodeKeyConstraintDescriptor, ownedNodeKeyIndex, name));

            default:
                throw new MalformedSchemaRuleException(format("Got unknown constraint rule type '%d'.", constraintRuleType));
            }
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void collectsDbStructure()
        public virtual void CollectsDbStructure()
        {
            // GIVEN
            DbStructureCollector collector = new DbStructureCollector();

            collector.VisitLabel(1, "Person");
            collector.VisitLabel(2, "City");
            collector.VisitPropertyKey(1, "name");
            collector.VisitPropertyKey(2, "income");
            collector.VisitRelationshipType(1, "LIVES_IN");
            collector.VisitRelationshipType(2, "FRIEND");
            collector.VisitIndex(TestIndexDescriptorFactory.uniqueForLabel(1, 1), ":Person(name)", 1.0d, 1L);
            collector.VisitUniqueConstraint(ConstraintDescriptorFactory.uniqueForLabel(2, 1), ":City(name)");
            collector.VisitNodeKeyConstraint(ConstraintDescriptorFactory.nodeKeyForLabel(2, 1), ":City(name)");
            collector.VisitIndex(TestIndexDescriptorFactory.forLabel(2, 2), ":City(income)", 0.2d, 1L);
            collector.VisitAllNodesCount(50);
            collector.VisitNodeCount(1, "Person", 20);
            collector.VisitNodeCount(2, "City", 30);
            collector.VisitRelCount(1, 2, -1, "(:Person)-[:FRIEND]->()", 500);

            // WHEN
            DbStructureLookup lookup = collector.Lookup();

            // THEN
            assertEquals(asList(of(1, "Person"), of(2, "City")), Iterators.asList(lookup.Labels()));
            assertEquals(asList(of(1, "name"), of(2, "income")), Iterators.asList(lookup.Properties()));
            assertEquals(asList(of(1, "LIVES_IN"), of(2, "FRIEND")), Iterators.asList(lookup.RelationshipTypes()));

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertArrayEquals(new string[] { "Person" }, lookup.KnownUniqueIndices().next().first());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertArrayEquals(new string[] { "name" }, lookup.KnownUniqueIndices().next().other());

//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            assertEquals(asList("City"), Iterators.asList(Iterators.map(Pair::first, lookup.KnownNodeKeyConstraints())));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertArrayEquals(new string[] { "name" }, lookup.KnownNodeKeyConstraints().next().other());

//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            assertEquals(asList("City"), Iterators.asList(Iterators.map(Pair::first, lookup.KnownUniqueConstraints())));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertArrayEquals(new string[] { "name" }, lookup.KnownUniqueConstraints().next().other());

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(new string[] { "City" }, lookup.KnownIndices().next().first());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertArrayEquals(new string[] { "income" }, lookup.KnownIndices().next().other());

            assertEquals(50, lookup.NodesAllCardinality());
            assertEquals(20, lookup.NodesWithLabelCardinality(1));
            assertEquals(30, lookup.NodesWithLabelCardinality(2));
            assertEquals(500, lookup.CardinalityByLabelsAndRelationshipType(1, 2, -1));
            assertEquals(1.0d, lookup.IndexUniqueValueSelectivity(1, 1), 0.01d);
            assertEquals(0.2d, lookup.IndexUniqueValueSelectivity(2, 2), 0.01d);
        }
Пример #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSetLatestConstraintRule() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSetLatestConstraintRule()
        {
            // Given
            SchemaRecord beforeRecords = Serialize(_rule, _id, true, true);
            SchemaRecord afterRecords  = Serialize(_rule, _id, true, false);

            when(_neoStores.SchemaStore).thenReturn(_schemaStore);
            when(_neoStores.MetaDataStore).thenReturn(_metaDataStore);

            ConstraintRule schemaRule = ConstraintRule.constraintRule(_id, ConstraintDescriptorFactory.uniqueForLabel(_labelId, _propertyKey), 0);

            // WHEN
            VisitSchemaRuleCommand(_storeApplier, new Command.SchemaRuleCommand(beforeRecords, afterRecords, schemaRule));

            // THEN
            verify(_schemaStore).updateRecord(Iterables.first(afterRecords));
            verify(_metaDataStore).LatestConstraintIntroducingTx = _txId;
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertParseRelationshipPropertyExistsRule(String serialized, String name) throws Exception
        private void AssertParseRelationshipPropertyExistsRule(string serialized, string name)
        {
            // GIVEN
            long ruleId      = 51;
            int  propertyKey = 6119;
            int  relTypeId   = 8512;
            ConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForRelType(relTypeId, propertyKey);

            sbyte[] bytes = DecodeBase64(serialized);

            // WHEN
            ConstraintRule deserialized = AssertConstraintRule(SchemaRuleSerialization.Deserialize(ruleId, ByteBuffer.wrap(bytes)));

            // THEN
            assertThat(deserialized.Id, equalTo(ruleId));
            assertThat(deserialized.ConstraintDescriptor, equalTo(constraint));
            assertThat(deserialized.Schema(), equalTo(constraint.Schema()));
            assertException(deserialized.getOwnedIndex, typeof(System.InvalidOperationException));
            assertThat(deserialized.Name, @is(name));
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertParseNodeKeyConstraintRule(String serialized, String name) throws org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException
        private void AssertParseNodeKeyConstraintRule(string serialized, string name)
        {
            // GIVEN
            long ruleId       = 1;
            int  propertyKey  = 3;
            int  labelId      = 55;
            long ownedIndexId = 2;
            NodeKeyConstraintDescriptor constraint = ConstraintDescriptorFactory.nodeKeyForLabel(labelId, propertyKey);

            sbyte[] bytes = DecodeBase64(serialized);

            // WHEN
            ConstraintRule deserialized = AssertConstraintRule(SchemaRuleSerialization.Deserialize(ruleId, ByteBuffer.wrap(bytes)));

            // THEN
            assertThat(deserialized.Id, equalTo(ruleId));
            assertThat(deserialized.ConstraintDescriptor, equalTo(constraint));
            assertThat(deserialized.Schema(), equalTo(constraint.Schema()));
            assertThat(deserialized.OwnedIndex, equalTo(ownedIndexId));
            assertThat(deserialized.Name, @is(name));
        }
Пример #8
0
 private CreateConstraintFailureException NodeKeyConstraintsNotAllowed(SchemaDescriptor descriptor)
 {
     // When creating a Node Key Constraint in Community Edition
     return(new CreateConstraintFailureException(ConstraintDescriptorFactory.existsForSchema(descriptor), ERROR_MESSAGE_NODE_KEY));
 }
Пример #9
0
 public static ConstraintRule UniquenessConstraintRule(long ruleId, int labelId, int propertyId, long indexId)
 {
     return(ConstraintRule.constraintRule(ruleId, ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyId), indexId));
 }
Пример #10
0
 private CreateConstraintFailureException PropertyExistenceConstraintsNotAllowed(SchemaDescriptor descriptor)
 {
     // When creating a Property Existence Constraint in Community Edition
     return(new CreateConstraintFailureException(ConstraintDescriptorFactory.existsForSchema(descriptor), ERROR_MESSAGE_EXISTS));
 }
Пример #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = IllegalArgumentException.class) public void nodeKeyConstraintRuleNameMustNotContainNullCharacter()
        public virtual void NodeKeyConstraintRuleNameMustNotContainNullCharacter()
        {
            string name = "a\0b";

            ConstraintRule.ConstraintRuleConflict(RULE_ID, ConstraintDescriptorFactory.nodeKeyForLabel(LABEL_ID, PROPERTY_ID_1), RULE_ID_2, name);
        }
Пример #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void rulesCreatedWithNullNameMustRetainComputedNameAfterDeserialisation() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RulesCreatedWithNullNameMustRetainComputedNameAfterDeserialisation()
        {
            assertThat(SerialiseAndDeserialise(ForLabel(LABEL_ID, PROPERTY_ID_1).withId(RULE_ID)).Name, @is("index_1"));
            assertThat(SerialiseAndDeserialise(UniqueForLabel(LABEL_ID, PROPERTY_ID_1).withIds(RULE_ID_2, RULE_ID)).Name, @is("index_2"));
            assertThat(SerialiseAndDeserialise(ForLabel(LABEL_ID, PROPERTY_ID_1, PROPERTY_ID_2).withId(RULE_ID)).Name, @is("index_1"));
            assertThat(SerialiseAndDeserialise(UniqueForLabel(LABEL_ID, PROPERTY_ID_1, PROPERTY_ID_2).withIds(RULE_ID_2, RULE_ID)).Name, @is("index_2"));
            assertThat(SerialiseAndDeserialise(ForLabel(LABEL_ID, IntStream.range(1, 200).toArray()).withId(RULE_ID)).Name, @is("index_1"));

            string name = null;

            assertThat(SerialiseAndDeserialise(ConstraintRule.constraintRule(RULE_ID, ConstraintDescriptorFactory.existsForLabel(LABEL_ID, PROPERTY_ID_1), name)).Name, @is("constraint_1"));
            assertThat(SerialiseAndDeserialise(ConstraintRule.ConstraintRuleConflict(RULE_ID_2, ConstraintDescriptorFactory.uniqueForLabel(LABEL_ID, PROPERTY_ID_1), RULE_ID, name)).Name, @is("constraint_2"));
            assertThat(SerialiseAndDeserialise(ConstraintRule.ConstraintRuleConflict(RULE_ID_2, ConstraintDescriptorFactory.nodeKeyForLabel(LABEL_ID, PROPERTY_ID_1), RULE_ID, name)).Name, @is("constraint_2"));
            assertThat(SerialiseAndDeserialise(ConstraintRule.constraintRule(RULE_ID_2, ConstraintDescriptorFactory.existsForRelType(REL_TYPE_ID, PROPERTY_ID_1), name)).Name, @is("constraint_2"));
            assertThat(SerialiseAndDeserialise(ConstraintRule.constraintRule(RULE_ID, ConstraintDescriptorFactory.existsForLabel(LABEL_ID, PROPERTY_ID_1, PROPERTY_ID_2), name)).Name, @is("constraint_1"));
            assertThat(SerialiseAndDeserialise(ConstraintRule.constraintRule(RULE_ID_2, ConstraintDescriptorFactory.existsForRelType(REL_TYPE_ID, PROPERTY_ID_1, PROPERTY_ID_2), name)).Name, @is("constraint_2"));
        }
Пример #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = IllegalArgumentException.class) public void constraintRuleNameMustNotContainNullCharacter()
        public virtual void ConstraintRuleNameMustNotContainNullCharacter()
        {
            string name = "a\0b";

            ConstraintRule.constraintRule(RULE_ID, ConstraintDescriptorFactory.existsForLabel(LABEL_ID, PROPERTY_ID_1), name);
        }
Пример #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void rulesCreatedWithNameMustRetainGivenNameAfterDeserialisation() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RulesCreatedWithNameMustRetainGivenNameAfterDeserialisation()
        {
            string name = "custom_rule";

            assertThat(SerialiseAndDeserialise(NamedForLabel(name, LABEL_ID, PROPERTY_ID_1).withId(RULE_ID)).Name, @is(name));
            assertThat(SerialiseAndDeserialise(NamedUniqueForLabel(name, LABEL_ID, PROPERTY_ID_1).withIds(RULE_ID_2, RULE_ID)).Name, @is(name));
            assertThat(SerialiseAndDeserialise(NamedForLabel(name, LABEL_ID, PROPERTY_ID_1, PROPERTY_ID_2).withId(RULE_ID)).Name, @is(name));
            assertThat(SerialiseAndDeserialise(NamedUniqueForLabel(name, LABEL_ID, PROPERTY_ID_1, PROPERTY_ID_2).withIds(RULE_ID_2, RULE_ID)).Name, @is(name));
            assertThat(SerialiseAndDeserialise(NamedForLabel(name, LABEL_ID, IntStream.range(1, 200).toArray()).withId(RULE_ID)).Name, @is(name));
            assertThat(SerialiseAndDeserialise(ConstraintRule.constraintRule(RULE_ID, ConstraintDescriptorFactory.existsForLabel(LABEL_ID, PROPERTY_ID_1), name)).Name, @is(name));
            assertThat(SerialiseAndDeserialise(ConstraintRule.ConstraintRuleConflict(RULE_ID_2, ConstraintDescriptorFactory.uniqueForLabel(LABEL_ID, PROPERTY_ID_1), RULE_ID, name)).Name, @is(name));
            assertThat(SerialiseAndDeserialise(ConstraintRule.ConstraintRuleConflict(RULE_ID_2, ConstraintDescriptorFactory.nodeKeyForLabel(LABEL_ID, PROPERTY_ID_1), RULE_ID, name)).Name, @is(name));
            assertThat(SerialiseAndDeserialise(ConstraintRule.constraintRule(RULE_ID_2, ConstraintDescriptorFactory.existsForRelType(REL_TYPE_ID, PROPERTY_ID_1), name)).Name, @is(name));
            assertThat(SerialiseAndDeserialise(ConstraintRule.constraintRule(RULE_ID, ConstraintDescriptorFactory.existsForLabel(LABEL_ID, PROPERTY_ID_1, PROPERTY_ID_2), name)).Name, @is(name));
            assertThat(SerialiseAndDeserialise(ConstraintRule.constraintRule(RULE_ID_2, ConstraintDescriptorFactory.existsForRelType(REL_TYPE_ID, PROPERTY_ID_1, PROPERTY_ID_2), name)).Name, @is(name));
        }
Пример #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowConcurrentViolationOfConstraint() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAllowConcurrentViolationOfConstraint()
        {
            // Given
            GraphDatabaseAPI graphDb = Db.GraphDatabaseAPI;

            System.Func <KernelTransaction> ktxSupplier = () => graphDb.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);

            Label  label            = label("Foo");
            string propertyKey      = "bar";
            string conflictingValue = "baz";

            // a constraint
            using (Transaction tx = graphDb.BeginTx())
            {
                graphDb.Schema().constraintFor(label).assertPropertyIsUnique(propertyKey).create();
                tx.Success();
            }

            // When
            using (Transaction tx = graphDb.BeginTx())
            {
                KernelTransaction ktx         = ktxSupplier();
                int             labelId       = ktx.TokenRead().nodeLabel(label.Name());
                int             propertyKeyId = ktx.TokenRead().propertyKey(propertyKey);
                IndexDescriptor index         = TestIndexDescriptorFactory.uniqueForLabel(labelId, propertyKeyId);
                Read            read          = ktx.DataRead();
                using (NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor())
                {
                    read.NodeIndexSeek(ktx.SchemaRead().index(labelId, propertyKeyId), cursor, IndexOrder.NONE, false, IndexQuery.exact(index.Schema().PropertyId, "The value is irrelevant, we just want to perform some sort of lookup against this " + "index"));
                }
                // then let another thread come in and create a node
                Threads.execute(Db =>
                {
                    using (Transaction transaction = Db.beginTx())
                    {
                        Db.createNode(label).setProperty(propertyKey, conflictingValue);
                        transaction.success();
                    }
                    return(null);
                }, graphDb).get();

                // before we create a node with the same property ourselves - using the same statement that we have
                // already used for lookup against that very same index
                long node = ktx.DataWrite().nodeCreate();
                ktx.DataWrite().nodeAddLabel(node, labelId);
                try
                {
                    ktx.DataWrite().nodeSetProperty(node, propertyKeyId, Values.of(conflictingValue));

                    fail("exception expected");
                }
                // Then
                catch (UniquePropertyValueValidationException e)
                {
                    assertEquals(ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyKeyId), e.Constraint());
                    IndexEntryConflictException conflict = Iterators.single(e.Conflicts().GetEnumerator());
                    assertEquals(Values.stringValue(conflictingValue), conflict.SinglePropertyValue);
                }

                tx.Success();
            }
        }
Пример #16
0
 internal override NodeKeyConstraintDescriptor NewConstraintObject(LabelSchemaDescriptor descriptor)
 {
     return(ConstraintDescriptorFactory.nodeKeyForSchema(descriptor));
 }
Пример #17
0
 protected internal override ConstraintDescriptor UniqueConstraintDescriptor(int labelId, params int[] propertyIds)
 {
     return(ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyIds));
 }
 public RelationshipPropertyExistenceException(RelationTypeSchemaDescriptor schema, ConstraintValidationException.Phase phase, long relationshipId) : base(ConstraintDescriptorFactory.existsForSchema(schema), phase, format("Relationship(%s)", relationshipId))
 {
     this._schema         = schema;
     this._relationshipId = relationshipId;
 }
Пример #19
0
 public static ConstraintRule RelPropertyExistenceConstraintRule(long ruleId, int labelId, int propertyId)
 {
     return(ConstraintRule.constraintRule(ruleId, ConstraintDescriptorFactory.existsForRelType(labelId, propertyId)));
 }
 public NodePropertyExistenceException(LabelSchemaDescriptor schema, ConstraintValidationException.Phase phase, long nodeId) : base(ConstraintDescriptorFactory.existsForSchema(schema), phase, format("Node(%d)", nodeId))
 {
     this._schema = schema;
     this._nodeId = nodeId;
 }