Skip to content

Commit

Permalink
GEODE-3: fix analyzeDataSerializable test for java 9 and later
Browse files Browse the repository at this point in the history
  • Loading branch information
jinmeiliao committed Sep 14, 2018
1 parent 71d9a0b commit 1541bc5
Showing 1 changed file with 43 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -621,38 +621,53 @@ public boolean toData(Object o, DataOutput out) throws IOException {
return true;
}
});
classesToSerializers.put(TimeUnit.NANOSECONDS.getClass().getName(), new WellKnownDS() {
@Override
public boolean toData(Object o, DataOutput out) throws IOException {
out.writeByte(DSCODE.TIME_UNIT.toByte());
out.writeByte(TIME_UNIT_NANOSECONDS);
return true;
}
});
classesToSerializers.put(TimeUnit.MICROSECONDS.getClass().getName(), new WellKnownDS() {
@Override
public boolean toData(Object o, DataOutput out) throws IOException {
out.writeByte(DSCODE.TIME_UNIT.toByte());
out.writeByte(TIME_UNIT_MICROSECONDS);
return true;
}
});
classesToSerializers.put(TimeUnit.MILLISECONDS.getClass().getName(), new WellKnownDS() {
@Override
public boolean toData(Object o, DataOutput out) throws IOException {
out.writeByte(DSCODE.TIME_UNIT.toByte());
out.writeByte(TIME_UNIT_MILLISECONDS);
return true;
}
});
classesToSerializers.put(TimeUnit.SECONDS.getClass().getName(), new WellKnownDS() {

WellKnownDS TIME_UNIT_SERIALIZER = new WellKnownDS() {
@Override
public boolean toData(Object o, DataOutput out) throws IOException {
out.writeByte(DSCODE.TIME_UNIT.toByte());
out.writeByte(TIME_UNIT_SECONDS);
TimeUnit timeUnit = (TimeUnit) o;
switch (timeUnit) {
case NANOSECONDS: {
out.writeByte(DSCODE.TIME_UNIT.toByte());
out.writeByte(TIME_UNIT_NANOSECONDS);
break;
}
case MICROSECONDS: {
out.writeByte(DSCODE.TIME_UNIT.toByte());
out.writeByte(TIME_UNIT_MICROSECONDS);
break;
}
case MILLISECONDS: {
out.writeByte(DSCODE.TIME_UNIT.toByte());
out.writeByte(TIME_UNIT_MILLISECONDS);
break;
}
case SECONDS: {
out.writeByte(DSCODE.TIME_UNIT.toByte());
out.writeByte(TIME_UNIT_SECONDS);
break;
}
// handles all other timeunits
default: {
writeGemFireEnum(timeUnit, out);
}
}
return true;
}
});
};

// in java 9 and above, TimeUnit implementation changes. the class name of these units are the
// same now.
if (TimeUnit.NANOSECONDS.getClass().getName().equals(TimeUnit.SECONDS.getClass().getName())) {
classesToSerializers.put(TimeUnit.class.getName(), TIME_UNIT_SERIALIZER);
}
// in java 8 and below
else {
classesToSerializers.put(TimeUnit.NANOSECONDS.getClass().getName(), TIME_UNIT_SERIALIZER);
classesToSerializers.put(TimeUnit.MICROSECONDS.getClass().getName(), TIME_UNIT_SERIALIZER);
classesToSerializers.put(TimeUnit.MILLISECONDS.getClass().getName(), TIME_UNIT_SERIALIZER);
classesToSerializers.put(TimeUnit.SECONDS.getClass().getName(), TIME_UNIT_SERIALIZER);
}
classesToSerializers.put("java.util.Date", new WellKnownPdxDS() {
@Override
public boolean toData(Object o, DataOutput out) throws IOException {
Expand Down

0 comments on commit 1541bc5

Please sign in to comment.