diff --git a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/PrimitiveSchemaTest.java b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/PrimitiveSchemaTest.java index a2efb251b5cca..d177195d0c77c 100644 --- a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/PrimitiveSchemaTest.java +++ b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/PrimitiveSchemaTest.java @@ -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; @@ -48,53 +49,65 @@ @Slf4j public class PrimitiveSchemaTest { - private static final Map> 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> 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> 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> 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 } }; }