@Test public void rulesCreatedWithoutNameMustHaveComputedName() { assertThat( indexRegular.getName(), is( "index_1" ) ); assertThat( indexUnique.getName(), is( "index_2" ) ); assertThat( indexCompositeRegular.getName(), is( "index_1" ) ); assertThat( indexCompositeUnique.getName(), is( "index_2" ) ); assertThat( indexBigComposite.getName(), is( "index_1" ) ); assertThat( constraintExistsLabel.getName(), is( "constraint_1" ) ); assertThat( constraintUniqueLabel.getName(), is( "constraint_2" ) ); assertThat( constraintNodeKeyLabel.getName(), is( "constraint_2" ) ); assertThat( constraintExistsRelType.getName(), is( "constraint_2" ) ); assertThat( constraintCompositeLabel.getName(), is( "constraint_1" ) ); assertThat( constraintCompositeRelType.getName(), is( "constraint_2" ) ); }
UTF8.putEncodedStringInto( constraintRule.getName(), target ); return target.array();
private void assertParseNodeKeyConstraintRule( String serialized, String name ) throws MalformedSchemaRuleException { // GIVEN long ruleId = 1; int propertyKey = 3; int labelId = 55; long ownedIndexId = 2; NodeKeyConstraintDescriptor constraint = ConstraintDescriptorFactory.nodeKeyForLabel( labelId, propertyKey ); byte[] bytes = decodeBase64( serialized ); // WHEN ConstraintRule deserialized = assertConstraintRule( SchemaRuleSerialization.deserialize( ruleId, ByteBuffer.wrap( bytes ) ) ); // THEN assertThat( deserialized.getId(), equalTo( ruleId ) ); assertThat( deserialized.getConstraintDescriptor(), equalTo( constraint ) ); assertThat( deserialized.schema(), equalTo( constraint.schema() ) ); assertThat( deserialized.getOwnedIndex(), equalTo( ownedIndexId ) ); assertThat( deserialized.getName(), is( name ) ); }
/** * Compute the byte size needed to serialize the provided ConstraintRule using serialize. * @param constraintRule the ConstraintRule * @return the byte size of ConstraintRule */ static int lengthOf( ConstraintRule constraintRule ) { int length = 4; // legacy label or relType id length += 1; // schema rule type length += 1; // constraint type ConstraintDescriptor constraintDescriptor = constraintRule.getConstraintDescriptor(); if ( constraintDescriptor.enforcesUniqueness() ) { length += 8; // owned index id } length += constraintDescriptor.schema().computeWith( schemaSizeComputer ); length += UTF8.computeRequiredByteBufferSize( constraintRule.getName() ); return length; }
private void assertParseUniqueConstraintRule( String serialized, String name ) throws MalformedSchemaRuleException { // GIVEN long ruleId = 1; int propertyKey = 3; int labelId = 55; long ownedIndexId = 2; UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel( labelId, propertyKey ); byte[] bytes = decodeBase64( serialized ); // WHEN ConstraintRule deserialized = assertConstraintRule( SchemaRuleSerialization.deserialize( ruleId, ByteBuffer.wrap( bytes ) ) ); // THEN assertThat( deserialized.getId(), equalTo( ruleId ) ); assertThat( deserialized.getConstraintDescriptor(), equalTo( constraint ) ); assertThat( deserialized.schema(), equalTo( constraint.schema() ) ); assertThat( deserialized.getOwnedIndex(), equalTo( ownedIndexId ) ); assertThat( deserialized.getName(), is( name ) ); }
private void assertParseNodePropertyExistsRule( String serialized, String name ) throws Exception { // GIVEN long ruleId = 87; int propertyKey = 51; int labelId = 45; ConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForLabel( labelId, propertyKey ); byte[] bytes = decodeBase64( serialized ); // WHEN ConstraintRule deserialized = assertConstraintRule( SchemaRuleSerialization.deserialize( ruleId, ByteBuffer.wrap( bytes ) ) ); // THEN assertThat( deserialized.getId(), equalTo( ruleId ) ); assertThat( deserialized.getConstraintDescriptor(), equalTo( constraint ) ); assertThat( deserialized.schema(), equalTo( constraint.schema() ) ); assertException( deserialized::getOwnedIndex, IllegalStateException.class ); assertThat( deserialized.getName(), is( name ) ); }
private void assertParseRelationshipPropertyExistsRule( String serialized, String name ) throws Exception { // GIVEN long ruleId = 51; int propertyKey = 6119; int relTypeId = 8512; ConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForRelType( relTypeId, propertyKey ); byte[] bytes = decodeBase64( serialized ); // WHEN ConstraintRule deserialized = assertConstraintRule( SchemaRuleSerialization.deserialize( ruleId, ByteBuffer.wrap( bytes ) ) ); // THEN assertThat( deserialized.getId(), equalTo( ruleId ) ); assertThat( deserialized.getConstraintDescriptor(), equalTo( constraint ) ); assertThat( deserialized.schema(), equalTo( constraint.schema() ) ); assertException( deserialized::getOwnedIndex, IllegalStateException.class ); assertThat( deserialized.getName(), is( name ) ); }
UTF8.putEncodedStringInto( constraintRule.getName(), target ); return target.array();
/** * Compute the byte size needed to serialize the provided ConstraintRule using serialize. * @param constraintRule the ConstraintRule * @return the byte size of ConstraintRule */ static int lengthOf( ConstraintRule constraintRule ) { int length = 4; // legacy label or relType id length += 1; // schema rule type length += 1; // constraint type ConstraintDescriptor constraintDescriptor = constraintRule.getConstraintDescriptor(); if ( constraintDescriptor.enforcesUniqueness() ) { length += 8; // owned index id } length += constraintDescriptor.schema().computeWith( schemaSizeComputer ); length += UTF8.computeRequiredByteBufferSize( constraintRule.getName() ); return length; }