-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kerem Sahin
committed
Feb 26, 2020
1 parent
e69def9
commit 71f2d14
Showing
7 changed files
with
112 additions
and
84 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
metadata-events/mxe-utils-avro-1.7/src/test/java/com/linkedin/metadata/EventUtilsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.linkedin.metadata; | ||
|
||
import com.linkedin.common.urn.CorpuserUrn; | ||
import com.linkedin.data.template.RecordTemplate; | ||
import com.linkedin.metadata.dao.utils.RecordUtils; | ||
import com.linkedin.mxe.MetadataAuditEvent; | ||
import com.linkedin.mxe.MetadataChangeEvent; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import org.apache.avro.Schema; | ||
import org.apache.avro.generic.GenericDatumReader; | ||
import org.apache.avro.generic.GenericRecord; | ||
import org.apache.avro.io.DatumReader; | ||
import org.apache.avro.io.DecoderFactory; | ||
import org.apache.avro.io.JsonDecoder; | ||
import org.testng.annotations.Test; | ||
|
||
import static com.linkedin.metadata.utils.TestUtils.*; | ||
import static org.testng.Assert.*; | ||
|
||
|
||
public class EventUtilsTests { | ||
|
||
@Test | ||
public void testAvroToPegasusMAE() throws IOException { | ||
GenericRecord record = genericRecordFromResource("test-avro2pegasus-mae.json", | ||
com.linkedin.pegasus2avro.mxe.MetadataAuditEvent.SCHEMA$); | ||
|
||
MetadataAuditEvent mae = EventUtils.avroToPegasusMAE(record); | ||
|
||
assertEquals( | ||
mae.getNewSnapshot().getDatasetSnapshot().getAspects().get(0).getOwnership().getOwners().get(0).getOwner(), | ||
new CorpuserUrn("foobar")); | ||
} | ||
|
||
@Test | ||
public void testAvroToPegasusMCE() throws IOException { | ||
GenericRecord record = genericRecordFromResource("test-avro2pegasus-mce.json", | ||
com.linkedin.pegasus2avro.mxe.MetadataChangeEvent.SCHEMA$); | ||
|
||
MetadataChangeEvent mce = EventUtils.avroToPegasusMCE(record); | ||
|
||
assertEquals( | ||
mce.getProposedSnapshot().getDatasetSnapshot().getAspects().get(0).getOwnership().getOwners().get(0).getOwner(), | ||
new CorpuserUrn("foobar")); | ||
} | ||
|
||
@Test | ||
public void testPegasusToAvroMAE() throws IOException { | ||
MetadataAuditEvent event = recordTemplateFromResource("test-pegasus2avro-mae.json", MetadataAuditEvent.class); | ||
|
||
GenericRecord record = EventUtils.pegasusToAvroMAE(event); | ||
|
||
assertEquals(record.getSchema(), com.linkedin.pegasus2avro.mxe.MetadataAuditEvent.SCHEMA$); | ||
assertNotNull(record.get("newSnapshot")); | ||
} | ||
|
||
@Test | ||
public void testPegasusToAvroMCE() throws IOException { | ||
MetadataChangeEvent event = recordTemplateFromResource("test-pegasus2avro-mce.json", MetadataChangeEvent.class); | ||
|
||
GenericRecord record = EventUtils.pegasusToAvroMCE(event); | ||
|
||
assertEquals(record.getSchema(), com.linkedin.pegasus2avro.mxe.MetadataChangeEvent.SCHEMA$); | ||
assertNotNull(record.get("proposedSnapshot")); | ||
} | ||
|
||
private GenericRecord genericRecordFromResource(String resourcePath, Schema schema) throws IOException { | ||
InputStream is = getClass().getClassLoader().getResourceAsStream(resourcePath); | ||
JsonDecoder decoder = DecoderFactory.get().jsonDecoder(schema, is); | ||
DatumReader<GenericRecord> reader = new GenericDatumReader<>(schema); | ||
return reader.read(null, decoder); | ||
} | ||
|
||
private <T extends RecordTemplate> T recordTemplateFromResource(String resourcePath, | ||
Class<? extends RecordTemplate> clazz) throws IOException { | ||
String json = loadJsonFromResource(resourcePath); | ||
return (T) RecordUtils.toRecordTemplate(clazz, json); | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
metadata-events/mxe-utils-avro-1.7/src/test/resources/old-mce-schema.avsc
This file was deleted.
Oops, something went wrong.
67 changes: 0 additions & 67 deletions
67
metadata-events/mxe-utils-avro-1.7/src/test/resources/old-mce.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 8 additions & 4 deletions
12
metadata-events/mxe-utils-avro-1.7/src/test/resources/test-avro2pegasus-mce.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 8 additions & 4 deletions
12
metadata-events/mxe-utils-avro-1.7/src/test/resources/test-pegasus2avro-mae.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 8 additions & 4 deletions
12
metadata-events/mxe-utils-avro-1.7/src/test/resources/test-pegasus2avro-mce.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters