static SchemaRule readSchemaRule( long id, Collection<DynamicRecord> records, byte[] buffer ) throws MalformedSchemaRuleException { ByteBuffer scratchBuffer = concatData( records, buffer ); return SchemaRuleSerialization.deserialize( id, scratchBuffer ); } }
private SchemaRule readSchemaRule( Collection<DynamicRecord> recordsBefore ) { // TODO: Why was this assertion here? // assert first(recordsBefore).inUse() : "Asked to deserialize schema records that were not in // use."; SchemaRule rule; ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] ); try { rule = SchemaRuleSerialization.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); } catch ( MalformedSchemaRuleException e ) { return null; } return rule; }
private SchemaRule readSchemaRule( Collection<DynamicRecord> recordsBefore ) { // TODO: Why was this assertion here? // assert first(recordsBefore).inUse() : "Asked to deserialize schema records that were not in // use."; SchemaRule rule; ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] ); try { rule = SchemaRuleSerialization.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); } catch ( MalformedSchemaRuleException e ) { return null; } return rule; }
private SchemaRule readSchemaRule( Collection<DynamicRecord> recordsBefore ) { // TODO: Why was this assertion here? // assert first(recordsBefore).inUse() : "Asked to deserialize schema records that were not in // use."; SchemaRule rule; ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] ); try { rule = SchemaRuleSerialization.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); } catch ( MalformedSchemaRuleException e ) { return null; } return rule; }
private SchemaRule readSchemaRule( Collection<DynamicRecord> recordsBefore ) { // TODO: Why was this assertion here? // assert first(recordsBefore).inUse() : "Asked to deserialize schema records that were not in // use."; SchemaRule rule; ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] ); try { rule = SchemaRuleSerialization.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); } catch ( MalformedSchemaRuleException e ) { return null; } return rule; }
private SchemaRule serialiseAndDeserialise( ConstraintRule constraintRule ) throws MalformedSchemaRuleException { ByteBuffer buffer = ByteBuffer.wrap( SchemaRuleSerialization.serialize( constraintRule ) ); return SchemaRuleSerialization.deserialize( constraintRule.getId(), buffer ); }
private SchemaRule serialiseAndDeserialise( StoreIndexDescriptor indexRule ) throws MalformedSchemaRuleException { ByteBuffer buffer = ByteBuffer.wrap( SchemaRuleSerialization.serialize( indexRule ) ); return SchemaRuleSerialization.deserialize( indexRule.getId(), buffer ); }
private void assertParseUniqueIndexRule( String serialized, String name ) throws MalformedSchemaRuleException { // GIVEN long ruleId = 33; long constraintId = 11; IndexDescriptor index = TestIndexDescriptorFactory.uniqueForLabel( 61, 988 ); IndexProviderDescriptor indexProvider = new IndexProviderDescriptor( "index-provider", "25.0" ); byte[] bytes = decodeBase64( serialized ); // WHEN StoreIndexDescriptor deserialized = assertIndexRule( SchemaRuleSerialization.deserialize( ruleId, ByteBuffer.wrap( bytes ) ) ); // THEN assertThat( deserialized.getId(), equalTo( ruleId ) ); assertThat( deserialized, equalTo( index ) ); assertThat( deserialized.schema(), equalTo( index.schema() ) ); assertThat( deserialized.providerDescriptor(), equalTo( indexProvider ) ); assertThat( deserialized.getOwningConstraint(), equalTo( constraintId ) ); assertThat( deserialized.getName(), is( name ) ); }
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 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 ) ); }
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 ) ); }
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 assertParseIndexRule( String serialized, String name ) throws Exception { // GIVEN long ruleId = 24; IndexDescriptor index = forLabel( 512, 4 ); IndexProviderDescriptor indexProvider = new IndexProviderDescriptor( "index-provider", "25.0" ); byte[] bytes = decodeBase64( serialized ); // WHEN StoreIndexDescriptor deserialized = assertIndexRule( SchemaRuleSerialization.deserialize( ruleId, ByteBuffer.wrap( bytes ) ) ); // THEN assertThat( deserialized.getId(), equalTo( ruleId ) ); assertThat( deserialized, equalTo( index ) ); assertThat( deserialized.schema(), equalTo( index.schema() ) ); assertThat( deserialized.providerDescriptor(), equalTo( indexProvider ) ); assertThat( deserialized.getName(), is( name ) ); assertException( deserialized::getOwningConstraint, IllegalStateException.class ); }
@Test public void storeAndLoad_Big_CompositeMultiTokenSchemaRule() throws Exception { // GIVEN StoreIndexDescriptor indexRule = forSchema( multiToken( IntStream.range( 1, 200 ).toArray(), EntityType.RELATIONSHIP, IntStream.range( 1, 200 ).toArray() ), PROVIDER_DESCRIPTOR ).withId( store.nextId() ); // WHEN StoreIndexDescriptor readIndexRule = (StoreIndexDescriptor) SchemaRuleSerialization.deserialize( indexRule.getId(), wrap( SchemaRuleSerialization.serialize( indexRule ) ) ); // THEN assertEquals( indexRule.getId(), readIndexRule.getId() ); assertEquals( indexRule.schema(), readIndexRule.schema() ); assertEquals( indexRule, readIndexRule ); assertEquals( indexRule.providerDescriptor(), readIndexRule.providerDescriptor() ); }
@Test public void storeAndLoad_Big_CompositeSchemaRule() throws Exception { // GIVEN StoreIndexDescriptor indexRule = forSchema( forLabel( 2, IntStream.range( 1, 200 ).toArray() ), PROVIDER_DESCRIPTOR ).withId( store.nextId() ); // WHEN StoreIndexDescriptor readIndexRule = (StoreIndexDescriptor) SchemaRuleSerialization.deserialize( indexRule.getId(), wrap( SchemaRuleSerialization.serialize( indexRule ) ) ); // THEN assertEquals( indexRule.getId(), readIndexRule.getId() ); assertEquals( indexRule.schema(), readIndexRule.schema() ); assertEquals( indexRule, readIndexRule ); assertEquals( indexRule.providerDescriptor(), readIndexRule.providerDescriptor() ); }
@Test public void storeAndLoadSchemaRule() throws Exception { // GIVEN StoreIndexDescriptor indexRule = forSchema( forLabel( 1, 4 ), PROVIDER_DESCRIPTOR ).withId( store.nextId() ); // WHEN StoreIndexDescriptor readIndexRule = (StoreIndexDescriptor) SchemaRuleSerialization.deserialize( indexRule.getId(), wrap( SchemaRuleSerialization.serialize( indexRule ) ) ); // THEN assertEquals( indexRule.getId(), readIndexRule.getId() ); assertEquals( indexRule.schema(), readIndexRule.schema() ); assertEquals( indexRule, readIndexRule ); assertEquals( indexRule.providerDescriptor(), readIndexRule.providerDescriptor() ); }
@Test public void storeAndLoadAnyTokenMultiTokenSchemaRule() throws Exception { // GIVEN int[] propertyIds = {4, 5, 6, 7}; int[] entityTokens = {}; StoreIndexDescriptor indexRule = forSchema( multiToken( entityTokens, EntityType.NODE, propertyIds ), PROVIDER_DESCRIPTOR ).withId( store.nextId() ); // WHEN StoreIndexDescriptor readIndexRule = (StoreIndexDescriptor) SchemaRuleSerialization.deserialize( indexRule.getId(), wrap( SchemaRuleSerialization.serialize( indexRule ) ) ); // THEN assertEquals( indexRule.getId(), readIndexRule.getId() ); assertEquals( indexRule.schema(), readIndexRule.schema() ); assertEquals( indexRule, readIndexRule ); assertEquals( indexRule.providerDescriptor(), readIndexRule.providerDescriptor() ); }
@Test public void storeAndLoadCompositeSchemaRule() throws Exception { // GIVEN int[] propertyIds = {4, 5, 6, 7}; StoreIndexDescriptor indexRule = forSchema( forLabel( 2, propertyIds ), PROVIDER_DESCRIPTOR ).withId( store.nextId() ); // WHEN StoreIndexDescriptor readIndexRule = (StoreIndexDescriptor) SchemaRuleSerialization.deserialize( indexRule.getId(), wrap( SchemaRuleSerialization.serialize( indexRule ) ) ); // THEN assertEquals( indexRule.getId(), readIndexRule.getId() ); assertEquals( indexRule.schema(), readIndexRule.schema() ); assertEquals( indexRule, readIndexRule ); assertEquals( indexRule.providerDescriptor(), readIndexRule.providerDescriptor() ); }
@Test public void storeAndLoadMultiTokenSchemaRule() throws Exception { // GIVEN int[] propertyIds = {4, 5, 6, 7}; int[] entityTokens = {2, 3, 4}; StoreIndexDescriptor indexRule = forSchema( multiToken( entityTokens, EntityType.RELATIONSHIP, propertyIds ), PROVIDER_DESCRIPTOR ).withId( store.nextId() ); // WHEN StoreIndexDescriptor readIndexRule = (StoreIndexDescriptor) SchemaRuleSerialization.deserialize( indexRule.getId(), wrap( SchemaRuleSerialization.serialize( indexRule ) ) ); // THEN assertEquals( indexRule.getId(), readIndexRule.getId() ); assertEquals( indexRule.schema(), readIndexRule.schema() ); assertEquals( indexRule, readIndexRule ); assertEquals( indexRule.providerDescriptor(), readIndexRule.providerDescriptor() ); }
static SchemaRule readSchemaRule( long id, Collection<DynamicRecord> records, byte[] buffer ) throws MalformedSchemaRuleException { ByteBuffer scratchBuffer = concatData( records, buffer ); return SchemaRuleSerialization.deserialize( id, scratchBuffer ); } }