Skip to content

Commit

Permalink
Issue apache#11037: Fix flaky test PrimitiveSchemaTest
Browse files Browse the repository at this point in the history
(cherry picked from commit 7141726)
  • Loading branch information
eolivelli committed Jun 23, 2021
1 parent d8beb1f commit 9628038
Showing 1 changed file with 57 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;

import io.netty.buffer.ByteBuf;
Expand Down Expand Up @@ -48,53 +49,65 @@
@Slf4j
public class PrimitiveSchemaTest {

private static final Map<Schema, List<Object>> testData = new HashMap() {
{
put(BooleanSchema.of(), Arrays.asList(false, true));
put(StringSchema.utf8(), Arrays.asList("my string"));
put(ByteSchema.of(), Arrays.asList((byte) 32767, (byte) -32768));
put(ShortSchema.of(), Arrays.asList((short) 32767, (short) -32768));
put(IntSchema.of(), Arrays.asList((int) 423412424, (int) -41243432));
put(LongSchema.of(), Arrays.asList(922337203685477580L, -922337203685477581L));
put(FloatSchema.of(), Arrays.asList(5678567.12312f, -5678567.12341f));
put(DoubleSchema.of(), Arrays.asList(5678567.12312d, -5678567.12341d));
put(BytesSchema.of(), Arrays.asList("my string".getBytes(UTF_8)));
put(ByteBufferSchema.of(), Arrays.asList(ByteBuffer.allocate(10).put("my string".getBytes(UTF_8))));
put(ByteBufSchema.of(), Arrays.asList(Unpooled.wrappedBuffer("my string".getBytes(UTF_8))));
put(DateSchema.of(), Arrays.asList(new Date(new java.util.Date().getTime() - 10000), new Date(new java.util.Date().getTime())));
put(TimeSchema.of(), Arrays.asList(new Time(new java.util.Date().getTime() - 10000), new Time(new java.util.Date().getTime())));
put(TimestampSchema.of(), Arrays.asList(new Timestamp(new java.util.Date().getTime()), new Timestamp(new java.util.Date().getTime())));
put(InstantSchema.of(), Arrays.asList(Instant.now(), Instant.now().minusSeconds(60*23L)));
put(LocalDateSchema.of(), Arrays.asList(LocalDate.now(), LocalDate.now().minusDays(2)));
put(LocalTimeSchema.of(), Arrays.asList(LocalTime.now(), LocalTime.now().minusHours(2)));
put(LocalDateTimeSchema.of(), Arrays.asList(LocalDateTime.now(), LocalDateTime.now().minusDays(2), LocalDateTime.now().minusWeeks(10)));
}
};

private static final Map<Schema, List<Object>> testData2 = new HashMap() {
{
put(Schema.BOOL, Arrays.asList(false, true));
put(Schema.STRING, Arrays.asList("my string"));
put(Schema.INT8, Arrays.asList((byte) 32767, (byte) -32768));
put(Schema.INT16, Arrays.asList((short) 32767, (short) -32768));
put(Schema.INT32, Arrays.asList((int) 423412424, (int) -41243432));
put(Schema.INT64, Arrays.asList(922337203685477580L, -922337203685477581L));
put(Schema.FLOAT, Arrays.asList(5678567.12312f, -5678567.12341f));
put(Schema.DOUBLE, Arrays.asList(5678567.12312d, -5678567.12341d));
put(Schema.BYTES, Arrays.asList("my string".getBytes(UTF_8)));
put(Schema.BYTEBUFFER, Arrays.asList(ByteBuffer.allocate(10).put("my string".getBytes(UTF_8))));
put(Schema.DATE, Arrays.asList(new Date(new java.util.Date().getTime() - 10000), new Date(new java.util.Date().getTime())));
put(Schema.TIME, Arrays.asList(new Time(new java.util.Date().getTime() - 10000), new Time(new java.util.Date().getTime())));
put(Schema.TIMESTAMP, Arrays.asList(new Timestamp(new java.util.Date().getTime() - 10000), new Timestamp(new java.util.Date().getTime())));
put(Schema.INSTANT, Arrays.asList(Instant.now(), Instant.now().minusSeconds(60*23L)));
put(Schema.LOCAL_DATE, Arrays.asList(LocalDate.now(), LocalDate.now().minusDays(2)));
put(Schema.LOCAL_TIME, Arrays.asList(LocalTime.now(), LocalTime.now().minusHours(2)));
put(Schema.LOCAL_DATE_TIME, Arrays.asList(LocalDateTime.now(), LocalDateTime.now().minusDays(2), LocalDateTime.now().minusWeeks(10)));
}
};

@DataProvider(name = "schemas")
public Object[][] schemas() {

// we are not using a static initialization block, see here:
// https://github.com/apache/pulsar/issues/11037

final Map<Schema, List<Object>> testData = new HashMap() {
{
put(BooleanSchema.of(), Arrays.asList(false, true));
put(StringSchema.utf8(), Arrays.asList("my string"));
put(ByteSchema.of(), Arrays.asList((byte) 32767, (byte) -32768));
put(ShortSchema.of(), Arrays.asList((short) 32767, (short) -32768));
put(IntSchema.of(), Arrays.asList((int) 423412424, (int) -41243432));
put(LongSchema.of(), Arrays.asList(922337203685477580L, -922337203685477581L));
put(FloatSchema.of(), Arrays.asList(5678567.12312f, -5678567.12341f));
put(DoubleSchema.of(), Arrays.asList(5678567.12312d, -5678567.12341d));
put(BytesSchema.of(), Arrays.asList("my string".getBytes(UTF_8)));
put(ByteBufferSchema.of(), Arrays.asList(ByteBuffer.allocate(10).put("my string".getBytes(UTF_8))));
put(ByteBufSchema.of(), Arrays.asList(Unpooled.wrappedBuffer("my string".getBytes(UTF_8))));
put(DateSchema.of(), Arrays.asList(new Date(new java.util.Date().getTime() - 10000), new Date(new java.util.Date().getTime())));
put(TimeSchema.of(), Arrays.asList(new Time(new java.util.Date().getTime() - 10000), new Time(new java.util.Date().getTime())));
put(TimestampSchema.of(), Arrays.asList(new Timestamp(new java.util.Date().getTime()), new Timestamp(new java.util.Date().getTime())));
put(InstantSchema.of(), Arrays.asList(Instant.now(), Instant.now().minusSeconds(60*23L)));
put(LocalDateSchema.of(), Arrays.asList(LocalDate.now(), LocalDate.now().minusDays(2)));
put(LocalTimeSchema.of(), Arrays.asList(LocalTime.now(), LocalTime.now().minusHours(2)));
put(LocalDateTimeSchema.of(), Arrays.asList(LocalDateTime.now(), LocalDateTime.now().minusDays(2), LocalDateTime.now().minusWeeks(10)));
}
};

final Map<Schema, List<Object>> testData2 = new HashMap() {
{
put(Schema.BOOL, Arrays.asList(false, true));
put(Schema.STRING, Arrays.asList("my string"));
put(Schema.INT8, Arrays.asList((byte) 32767, (byte) -32768));
put(Schema.INT16, Arrays.asList((short) 32767, (short) -32768));
put(Schema.INT32, Arrays.asList((int) 423412424, (int) -41243432));
put(Schema.INT64, Arrays.asList(922337203685477580L, -922337203685477581L));
put(Schema.FLOAT, Arrays.asList(5678567.12312f, -5678567.12341f));
put(Schema.DOUBLE, Arrays.asList(5678567.12312d, -5678567.12341d));
put(Schema.BYTES, Arrays.asList("my string".getBytes(UTF_8)));
put(Schema.BYTEBUFFER, Arrays.asList(ByteBuffer.allocate(10).put("my string".getBytes(UTF_8))));
put(Schema.DATE, Arrays.asList(new Date(new java.util.Date().getTime() - 10000), new Date(new java.util.Date().getTime())));
put(Schema.TIME, Arrays.asList(new Time(new java.util.Date().getTime() - 10000), new Time(new java.util.Date().getTime())));
put(Schema.TIMESTAMP, Arrays.asList(new Timestamp(new java.util.Date().getTime() - 10000), new Timestamp(new java.util.Date().getTime())));
put(Schema.INSTANT, Arrays.asList(Instant.now(), Instant.now().minusSeconds(60*23L)));
put(Schema.LOCAL_DATE, Arrays.asList(LocalDate.now(), LocalDate.now().minusDays(2)));
put(Schema.LOCAL_TIME, Arrays.asList(LocalTime.now(), LocalTime.now().minusHours(2)));
put(Schema.LOCAL_DATE_TIME, Arrays.asList(LocalDateTime.now(), LocalDateTime.now().minusDays(2), LocalDateTime.now().minusWeeks(10)));
}
};

for (Schema schema : testData.keySet()) {
assertNotNull(schema);
}
for (Schema schema : testData2.keySet()) {
assertNotNull(schema);
}

return new Object[][] { { testData }, { testData2 } };
}

Expand Down

0 comments on commit 9628038

Please sign in to comment.