Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test for flat record reader schema evolution #609

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ protected Object parseFlatRecord(HollowSchema recordSchema, FlatRecordReader rea
if (schema.numFields() == 1 && schema.getFieldType(0) != HollowObjectSchema.FieldType.REFERENCE) {
obj = mappedFields.get(0).parseBoxedWrapper(reader);
} else {
obj = clazz.newInstance();
try {
obj = clazz.newInstance();
} catch (InstantiationException e) {
throw new IllegalStateException("Default constructor for class " + clazz.getName() + " not accessible", e);
}
for (int i = 0; i < recordObjectSchema.numFields(); i++) {
int posInPojoSchema = schema.getPosition(recordObjectSchema.getFieldName(i));
if (posInPojoSchema != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,66 @@ public void setUp() {
mapper.getStateEngine(), new FakeHollowSchemaIdentifierMapper(mapper.getStateEngine()));
}

static class V0 {
@HollowPrimaryKey(fields={"id"})
private static class Movie {
private int id;
private String name;
int year;

public Movie(int id, String name, int year) {
this.id = id;
this.name = name;
this.year = year;
}
}
}

static class V1 {
@HollowPrimaryKey(fields={"id"})
private static class Movie {
private String name;
private int id;

public Movie() { }

public Movie(String name, int id) {
this.name = name;
this.id = id;
}
}
}

@Test
public void testSimpleSchemaEvolution() {
HollowObjectMapper mapper0 = new HollowObjectMapper(new HollowWriteStateEngine());
mapper0.initializeTypeState(V0.Movie.class);

FlatRecordWriter myFlatRecordWriter = new FlatRecordWriter(
mapper0.getStateEngine(), new FakeHollowSchemaIdentifierMapper(mapper0.getStateEngine()));

V0.Movie actual = new V0.Movie(1, "Serde", 2023);
mapper0.writeFlat(actual, myFlatRecordWriter);
FlatRecord fr = myFlatRecordWriter.generateFlatRecord();

HollowObjectMapper myMapper1 = new HollowObjectMapper(new HollowWriteStateEngine());
myMapper1.initializeTypeState(V1.Movie.class);

V1.Movie expected = myMapper1.readFlat(fr);
Assert.assertEquals(expected.id, actual.id);
Assert.assertEquals(expected.name, actual.name);
}

@Test (expected = RuntimeException.class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Test (expected = RuntimeException.class)
@Test (expected = IllegalStateException.class)

?

public void testNoDefaultConstructor() {
HollowObjectMapper myMapper = new HollowObjectMapper(new HollowWriteStateEngine());
myMapper.initializeTypeState(V0.Movie.class);
FlatRecordWriter myFlatRecordWriter = new FlatRecordWriter(
myMapper.getStateEngine(), new FakeHollowSchemaIdentifierMapper(myMapper.getStateEngine()));
FlatRecord fr = myFlatRecordWriter.generateFlatRecord();
myMapper.readFlat(fr);
}

@Test
public void testSimpleTypes() {
TypeWithAllSimpleTypes typeWithAllSimpleTypes = new TypeWithAllSimpleTypes();
Expand Down