AvroConverter { public AuthorizationContext convert(AvroAuthzContext authzContext) { if (authzContext == null) return null; Set<String> roles = new HashSet<String>(); for (String role : authzContext.getRoles()) { roles.add(role); } return new AuthorizationContext(authzContext.getName(), authzContext.getTenant(), roles); } AvroConverter(); AuthorizationContext convert(AvroAuthzContext authzContext); AvroAuthzContext convert(AuthorizationContext authzContext); ByteBuffer convert(Record record, LRepository repository); ByteBuffer convert(IdRecord idRecord, LRepository repository); Record convertRecord(ByteBuffer recordData, LRepository repository); IdRecord convertIdRecord(ByteBuffer avroIdRecord, LRepository repository); List<AvroMutationCondition> convert(Record parentRecord, List<MutationCondition> conditions,
            LRepository repository); List<Record> convertAvroRecords(List<ByteBuffer> avroRecords, LRepository repository); List<ByteBuffer> convertRecords(Collection<Record> records, LRepository repository); FieldType convert(AvroFieldType avroFieldType, TypeManager typeManager); Scope convert(AvroScope scope); AvroFieldType convert(FieldType fieldType); AvroScope convert(Scope scope); RecordType convert(AvroRecordType avroRecordType, TypeManager typeManager); AvroRecordType convert(RecordType recordType); AvroFieldAndRecordTypes convertFieldAndRecordTypes(Pair<List<FieldType>, List<RecordType>> types); Pair<List<FieldType>, List<RecordType>> convertAvroFieldAndRecordTypes(AvroFieldAndRecordTypes types,
            TypeManager typeManager); AvroTypeBucket convertTypeBucket(TypeBucket typeBucket); TypeBucket convertAvroTypeBucket(AvroTypeBucket avroTypeBucket, TypeManager  typeManager); ValueType convert(AvroValueType valueType, TypeManager typeManager); AvroValueType convert(ValueType valueType); QName convert(AvroQName name); AvroQName convert(QName name); AvroSupertype convert(Entry<SchemaId, Long> supertypeEntry); FieldTypeEntry convert(AvroFieldTypeEntry avroFieldTypeEntry, TypeManager typeManager); AvroFieldTypeEntry convert(FieldTypeEntry fieldTypeEntry); static AvroGenericException convertOtherException(Throwable throwable); RuntimeException convert(AvroGenericException avroException); RemoteException convert(AvroRemoteException exception); AvroRepositoryException convert(RepositoryException exception); RepositoryException convert(AvroRepositoryException avroException); AvroInterruptedException convert(InterruptedException exception); AvroIOException convert(IOException exception); IOException convert(AvroIOException avroException); ByteBuffer convert(RecordId recordId); Long convertAvroVersion(long avroVersion); long convertVersion(Long version); List<FieldType> convertAvroFieldTypes(List<AvroFieldType> avroFieldTypes, TypeManager typeManager); List<RecordType> convertAvroRecordTypes(List<AvroRecordType> avroRecordTypes, TypeManager typeManager); List<AvroFieldType> convertFieldTypes(Collection<FieldType> fieldTypes); List<AvroRecordType> convertRecordTypes(Collection<RecordType> recordTypes); SchemaId convert(AvroSchemaId avroSchemaId); AvroSchemaId convert(SchemaId schemaId); QName[] convert(List<AvroQName> avroNames); List<String> convert(Set<RecordId> recordIds); CompareOp convert(AvroCompareOp op); List<MutationCondition> convertFromAvro(List<AvroMutationCondition> avroConditions, LRepository repository); AvroTableCreateDescriptor convert(TableCreateDescriptor descriptor); TableCreateDescriptor convert(AvroTableCreateDescriptor avroDescriptor); AvroCompareOp convert(CompareOp op); RecordId convertAvroRecordId(ByteBuffer recordId, LRepository repository); Set<RecordId> convertAvroRecordIds(List<String> avroRecordIds, LRepository repository);  }
@Test public void testQName() { control.replay(); converter = new AvroConverter(); QName qname = new QName("namespace", "name"); AvroQName avroQName = new AvroQName(); avroQName.namespace = "namespace"; avroQName.name = "name"; assertEquals(avroQName, converter.convert(qname)); assertEquals(qname, converter.convert(avroQName)); }
@Test public void testValueType() throws Exception { ValueType valueType = new StringValueType(); typeManager.getValueType("STRING"); expectLastCall().andReturn(valueType); control.replay(); converter = new AvroConverter(); AvroValueType avroValueType = new AvroValueType(); avroValueType.valueType = "STRING"; assertEquals(valueType, converter.convert(avroValueType, typeManager)); assertEquals(avroValueType, converter.convert(valueType)); control.verify(); }
@Test public void testFieldTypeEntry() { SchemaId id = new SchemaIdImpl(UUID.randomUUID()); FieldTypeEntry fieldTypeEntry = new FieldTypeEntryImpl(id, true); typeManager.newFieldTypeEntry(id, true); expectLastCall().andReturn(fieldTypeEntry); control.replay(); converter = new AvroConverter(); AvroFieldTypeEntry avroFieldTypeEntry = new AvroFieldTypeEntry(); AvroSchemaId avroSchemaId = new AvroSchemaId(); avroSchemaId.idBytes = ByteBuffer.wrap(id.getBytes()); avroFieldTypeEntry.id = avroSchemaId; avroFieldTypeEntry.mandatory = true; assertEquals(fieldTypeEntry, converter.convert(avroFieldTypeEntry, typeManager)); assertEquals(avroFieldTypeEntry, converter.convert(fieldTypeEntry)); control.verify(); }
@Test public void testFieldType() throws Exception { ValueType valueType = new StringValueType(); typeManager.getValueType("STRING"); expectLastCall().andReturn(valueType); QName name = new QName("aNamespace", "aName"); SchemaId fieldTypeId = new SchemaIdImpl(UUID.randomUUID()); FieldType fieldType = new FieldTypeImpl(fieldTypeId, valueType, name, Scope.NON_VERSIONED); typeManager.newFieldType(fieldTypeId, valueType, name, Scope.NON_VERSIONED); expectLastCall().andReturn(fieldType); control.replay(); converter = new AvroConverter(); AvroFieldType avroFieldType = new AvroFieldType(); AvroSchemaId avroSchemaId = new AvroSchemaId(); avroSchemaId.idBytes = ByteBuffer.wrap(fieldTypeId.getBytes()); avroFieldType.id = avroSchemaId; AvroQName avroQName = new AvroQName(); avroQName.namespace = "aNamespace"; avroQName.name = "aName"; avroFieldType.name = avroQName; avroFieldType.scope = AvroScope.NON_VERSIONED; AvroValueType avroValueType = new AvroValueType(); avroValueType.valueType = "STRING"; avroFieldType.valueType = avroValueType; assertEquals(fieldType, converter.convert(avroFieldType, typeManager)); assertEquals(avroFieldType, converter.convert(fieldType)); control.verify(); }
@Test public void testFieldTypeWithoutId() throws Exception { ValueType valueType = new StringValueType(); typeManager.getValueType("LIST<STRING>"); expectLastCall().andReturn(valueType); QName name = new QName("aNamespace", "aName"); FieldType fieldType = new FieldTypeImpl(null, valueType, name, Scope.NON_VERSIONED); typeManager.newFieldType(valueType, name, Scope.NON_VERSIONED); expectLastCall().andReturn(fieldType); control.replay(); converter = new AvroConverter(); AvroFieldType avroFieldType = new AvroFieldType(); AvroQName avroQName = new AvroQName(); avroQName.namespace = "aNamespace"; avroQName.name = "aName"; avroFieldType.name = avroQName; avroFieldType.scope = AvroScope.NON_VERSIONED; AvroValueType avroValueType = new AvroValueType(); avroValueType.valueType = "LIST<STRING>"; avroFieldType.valueType = avroValueType; converter.convert(avroFieldType, typeManager); control.verify(); }
@Test public void testEmptyRecordType() throws Exception { QName name = new QName("aNamespace", "aName"); SchemaId id = new SchemaIdImpl(UUID.randomUUID()); RecordType recordType = new RecordTypeImpl(id, name); typeManager.newRecordType(id, name); expectLastCall().andReturn(recordType); control.replay(); converter = new AvroConverter(); AvroRecordType avroRecordType = new AvroRecordType(); AvroSchemaId avroSchemaId = new AvroSchemaId(); avroSchemaId.idBytes = ByteBuffer.wrap(id.getBytes()); avroRecordType.id = avroSchemaId; AvroQName avroQName = new AvroQName(); avroQName.namespace = "aNamespace"; avroQName.name = "aName"; avroRecordType.name = avroQName; avroRecordType.fieldTypeEntries = new GenericData.Array<AvroFieldTypeEntry>(0, Schema.createArray(AvroFieldTypeEntry.SCHEMA$)); avroRecordType.supertypes = new GenericData.Array<AvroSupertype>(0, Schema.createArray(AvroSupertype.SCHEMA$)); assertEquals(recordType, converter.convert(avroRecordType, typeManager)); assertEquals(avroRecordType, converter.convert(recordType)); control.verify(); }
@Test public void testRecordTypeVersion() throws Exception { QName name = new QName("aNamespace", "aName"); SchemaId id = new SchemaIdImpl(UUID.randomUUID()); RecordType recordType = new RecordTypeImpl(id, name); typeManager.newRecordType(id, name); expectLastCall().andReturn(recordType); control.replay(); converter = new AvroConverter(); recordType.setVersion(1L); AvroRecordType avroRecordType = new AvroRecordType(); AvroSchemaId avroSchemaId = new AvroSchemaId(); avroSchemaId.idBytes = ByteBuffer.wrap(id.getBytes()); avroRecordType.id = avroSchemaId; AvroQName avroQName = new AvroQName(); avroQName.namespace = "aNamespace"; avroQName.name = "aName"; avroRecordType.name = avroQName; avroRecordType.version = 1L; avroRecordType.fieldTypeEntries = new GenericData.Array<AvroFieldTypeEntry>(0, Schema.createArray(AvroFieldTypeEntry.SCHEMA$)); avroRecordType.supertypes = new GenericData.Array<AvroSupertype>(0, Schema.createArray(AvroSupertype.SCHEMA$)); assertEquals(recordType, converter.convert(avroRecordType, typeManager)); assertEquals(avroRecordType, converter.convert(recordType)); control.verify(); }
@Test public void testRecordTypeFieldTypeEntries() throws Exception { QName name = new QName("aNamespace", "aName"); SchemaId recordTypeId = new SchemaIdImpl(UUID.randomUUID()); RecordType recordType = new RecordTypeImpl(recordTypeId, name); typeManager.newRecordType(recordTypeId, name); expectLastCall().andReturn(recordType); SchemaId fieldTypeId1 = new SchemaIdImpl(UUID.randomUUID()); SchemaId fieldTypeId2 = new SchemaIdImpl(UUID.randomUUID()); FieldTypeEntryImpl fieldTypeEntry1 = new FieldTypeEntryImpl(fieldTypeId1, true); FieldTypeEntryImpl fieldTypeEntry2 = new FieldTypeEntryImpl(fieldTypeId2, false); typeManager.newFieldTypeEntry(fieldTypeId1, true); expectLastCall().andReturn(fieldTypeEntry1); typeManager.newFieldTypeEntry(fieldTypeId2, false); expectLastCall().andReturn(fieldTypeEntry2); control.replay(); converter = new AvroConverter(); recordType.addFieldTypeEntry(fieldTypeEntry1); recordType.addFieldTypeEntry(fieldTypeEntry2); AvroRecordType avroRecordType = new AvroRecordType(); AvroSchemaId avroRecordTypeId = new AvroSchemaId(); avroRecordTypeId.idBytes = ByteBuffer.wrap(recordTypeId.getBytes()); avroRecordType.id = avroRecordTypeId; AvroQName avroQName = new AvroQName(); avroQName.namespace = "aNamespace"; avroQName.name = "aName"; avroRecordType.name = avroQName; avroRecordType.fieldTypeEntries = new GenericData.Array<AvroFieldTypeEntry>(0, Schema.createArray(AvroFieldTypeEntry.SCHEMA$)); AvroFieldTypeEntry avroFieldTypeEntry = new AvroFieldTypeEntry(); AvroSchemaId avroFieldTypeId1 = new AvroSchemaId(); avroFieldTypeId1.idBytes = ByteBuffer.wrap(fieldTypeId1.getBytes()); avroFieldTypeEntry.id = avroFieldTypeId1; avroFieldTypeEntry.mandatory = true; avroRecordType.fieldTypeEntries.add(avroFieldTypeEntry); Set<AvroFieldTypeEntry> expectedFieldTypeEntries = new HashSet<AvroFieldTypeEntry>(); expectedFieldTypeEntries.add(avroFieldTypeEntry); avroFieldTypeEntry = new AvroFieldTypeEntry(); AvroSchemaId avroFieldTypeId2 = new AvroSchemaId(); avroFieldTypeId2.idBytes = ByteBuffer.wrap(fieldTypeId2.getBytes()); avroFieldTypeEntry.id = avroFieldTypeId2; avroFieldTypeEntry.mandatory = false; avroRecordType.fieldTypeEntries.add(avroFieldTypeEntry); expectedFieldTypeEntries.add(avroFieldTypeEntry); avroRecordType.supertypes = new GenericData.Array<AvroSupertype>(0, Schema.createArray(AvroSupertype.SCHEMA$)); assertEquals(recordType, converter.convert(avroRecordType, typeManager)); AvroRecordType actualAvroRecordType = converter.convert(recordType); List<AvroFieldTypeEntry> fieldTypeEntries = actualAvroRecordType.fieldTypeEntries; assertEquals(2, fieldTypeEntries.size()); Set<AvroFieldTypeEntry> actualFieldTypeEntries = new HashSet<AvroFieldTypeEntry>(); for (AvroFieldTypeEntry entry : fieldTypeEntries) { actualFieldTypeEntries.add(entry); } assertEquals(expectedFieldTypeEntries, actualFieldTypeEntries); control.verify(); }
@Test public void testRecordTypeSupertypes() throws Exception { QName name = new QName("aNamespace", "aName"); SchemaId recordTypeId = new SchemaIdImpl(UUID.randomUUID()); RecordType recordType = new RecordTypeImpl(recordTypeId, name); typeManager.newRecordType(recordTypeId, name); expectLastCall().andReturn(recordType); control.replay(); converter = new AvroConverter(); SchemaId supertypeId1 = new SchemaIdImpl(UUID.randomUUID()); recordType.addSupertype(supertypeId1, 1L); SchemaId supertypeId2 = new SchemaIdImpl(UUID.randomUUID()); recordType.addSupertype(supertypeId2, 2L); AvroRecordType avroRecordType = new AvroRecordType(); AvroSchemaId avroRecordTypeId = new AvroSchemaId(); avroRecordTypeId.idBytes = ByteBuffer.wrap(recordTypeId.getBytes()); avroRecordType.id = avroRecordTypeId; AvroQName avroQName = new AvroQName(); avroQName.namespace = "aNamespace"; avroQName.name = "aName"; avroRecordType.name = avroQName; avroRecordType.fieldTypeEntries = new GenericData.Array<AvroFieldTypeEntry>(0, Schema.createArray(AvroFieldTypeEntry.SCHEMA$)); avroRecordType.supertypes = new GenericData.Array<AvroSupertype>(0, Schema.createArray(AvroSupertype.SCHEMA$)); AvroSupertype avroSupertype1 = new AvroSupertype(); AvroSchemaId avroSupertypeId1 = new AvroSchemaId(); avroSupertypeId1.idBytes = ByteBuffer.wrap(supertypeId1.getBytes()); avroSupertype1.recordTypeId = avroSupertypeId1; avroSupertype1.recordTypeVersion = 1L; avroRecordType.supertypes.add(avroSupertype1); Set<AvroSupertype> expectedSupertypes = new HashSet<AvroSupertype>(); expectedSupertypes.add(avroSupertype1); AvroSupertype avroSupertype2 = new AvroSupertype(); AvroSchemaId avroSupertypeId2 = new AvroSchemaId(); avroSupertypeId2.idBytes = ByteBuffer.wrap(supertypeId2.getBytes()); avroSupertype2.recordTypeId = avroSupertypeId2; avroSupertype2.recordTypeVersion = 2L; avroRecordType.supertypes.add(avroSupertype2); expectedSupertypes.add(avroSupertype2); assertEquals(recordType, converter.convert(avroRecordType, typeManager)); AvroRecordType actualAvroRecordType = converter.convert(recordType); List<AvroSupertype> supertypes = actualAvroRecordType.supertypes; assertEquals(2, supertypes.size()); Set<AvroSupertype> actualSupertypes = new HashSet<AvroSupertype>(); for (AvroSupertype entry : supertypes) { actualSupertypes.add(entry); } assertEquals(expectedSupertypes, actualSupertypes); control.verify(); }