Search in sources :

Example 1 with BLOB_MESSAGE

use of net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BLOB_MESSAGE in project providence by morimekta.

the class MessageRowMapperTest method testDefaultMapping.

@Test
public void testDefaultMapping() {
    generator.setFillRate(1.0).setMaxCollectionItems(16).withGenerator(CompactFields.kDescriptor, g -> {
        g.setValueGenerator(CompactFields._Field.NAME, ctx -> ctx.getFairy().textProducer().latinWord());
        g.setValueGenerator(CompactFields._Field.LABEL, ctx -> ctx.getFairy().textProducer().word());
    }).withGenerator(NormalFields.kDescriptor, g -> {
        g.setValueGenerator(NormalFields._Field.NAME, ctx -> ctx.getFairy().textProducer().latinWord());
        g.setValueGenerator(NormalFields._Field.LABEL, ctx -> ctx.getFairy().textProducer().word());
    });
    OptionalFields expected = generator.generate(OptionalFields.kDescriptor).mutate().setId(1234).setTimestampS((int) clock.instant().getEpochSecond()).setTimestampMs(clock.instant().getEpochSecond() * 1000).build();
    OptionalFields empty = OptionalFields.builder().setId(2345).build();
    try (Handle handle = db.getDBI().open()) {
        handle.createUpdate("INSERT INTO mappings_v3.default_mappings (" + "  id, present, tiny, small, medium, large, real," + "  fib, name, data, compact," + "  timestamp_s, timestamp_ms," + "  binary_message, blob_message, other_message," + "  blob_data, base64_data, int_bool" + ") VALUES (" + "  :e.id," + "  :e.present," + "  :e.tiny," + "  :e.small," + "  :e.medium," + "  :e.large," + "  :e.real," + "  :e.fib," + "  :e.name," + "  :e.data," + "  :e.message," + "  :timestamp_s," + "  :e.timestamp_ms," + "  :e.binary_message," + "  :e.blob_message," + "  :e.clob_message," + "  :e.blob_data," + "  :e.base64_data," + "  :e.int_bool" + ")").bind("timestamp_s", toField(expected, TIMESTAMP_S, Types.TIMESTAMP)).bindNamedArgumentFinder(forMessage("e", expected, withType(TIMESTAMP_MS, Types.TIMESTAMP), withType(BINARY_MESSAGE, Types.BINARY), withType(BLOB_MESSAGE, Types.BLOB), withType(CLOB_MESSAGE, Types.CLOB), withType(BLOB_DATA, Types.BLOB), withType(BASE64_DATA, Types.VARCHAR))).execute();
        handle.createUpdate("INSERT INTO mappings_v3.default_mappings (" + "  id, present, tiny, small, medium, large, real," + "  fib, name, data, compact," + "  timestamp_s, timestamp_ms," + "  binary_message, blob_message, other_message," + "  blob_data, base64_data, int_bool" + ") VALUES (" + "  :id," + "  :present," + "  :tiny," + "  :small," + "  :medium," + "  :large," + "  :real," + "  :fib," + "  :name," + "  :data," + "  :message," + "  :timestamp_s," + "  :timestamp_ms," + "  :binary_message," + "  :blob_message," + "  :clob_message," + "  :blob_data," + "  :base64_data," + "  :int_bool" + ")").bind("timestamp_s", toField(empty, TIMESTAMP_S, Types.TIMESTAMP)).bindNamedArgumentFinder(forMessage(empty, withType(TIMESTAMP_MS, Types.TIMESTAMP), withType(BINARY_MESSAGE, Types.BINARY), withType(BLOB_MESSAGE, Types.BLOB), withType(CLOB_MESSAGE, Types.CLOB), withType(BLOB_DATA, Types.BLOB), withType(BASE64_DATA, Types.VARCHAR), withType(INT_BOOL, Types.INTEGER))).execute();
        OptionalFields val = handle.createQuery("SELECT m.* FROM mappings_v3.default_mappings m WHERE id = :id").bind("id", toField(expected, ID)).map(toMessage("default_mappings", OptionalFields.kDescriptor, columnsFromAllFields(), withColumn("compact", MESSAGE), withColumn("other_message", CLOB_MESSAGE))).findFirst().orElseThrow(() -> new AssertionError("No content in default_mappings"));
        OptionalFields val2 = handle.createQuery("SELECT * FROM mappings_v3.default_mappings WHERE id = :id").bind("id", toField(empty, ID)).map(toMessage(OptionalFields.kDescriptor, columnsFromAllFields(), withColumn("compact", MESSAGE), withColumn("other_message", CLOB_MESSAGE))).findFirst().orElseThrow(() -> new AssertionError("No content in default_mappings"));
        assertThat(val, is(equalToMessage(expected)));
        assertThat(val2, is(equalToMessage(empty)));
    }
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ID(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.ID) TIMESTAMP_MS(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.TIMESTAMP_MS) ProvidenceJdbi.withType(net.morimekta.providence.jdbi.v3.ProvidenceJdbi.withType) ProvidenceJdbi.forMessage(net.morimekta.providence.jdbi.v3.ProvidenceJdbi.forMessage) CLOB_MESSAGE(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.CLOB_MESSAGE) BLOB_DATA(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BLOB_DATA) Assert.assertThat(org.junit.Assert.assertThat) Handle(org.jdbi.v3.core.Handle) ProvidenceJdbi.toField(net.morimekta.providence.jdbi.v3.ProvidenceJdbi.toField) TIMESTAMP_S(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.TIMESTAMP_S) INT_BOOL(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.INT_BOOL) ProvidenceJdbi.withColumn(net.morimekta.providence.jdbi.v3.ProvidenceJdbi.withColumn) OptionalFields(net.morimekta.test.providence.storage.jdbc.OptionalFields) Test(org.junit.Test) BASE64_DATA(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BASE64_DATA) NormalFields(net.morimekta.test.providence.storage.jdbc.NormalFields) BINARY_MESSAGE(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BINARY_MESSAGE) BLOB_MESSAGE(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BLOB_MESSAGE) ProvidenceJdbi.toMessage(net.morimekta.providence.jdbi.v3.ProvidenceJdbi.toMessage) MESSAGE(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.MESSAGE) Rule(org.junit.Rule) SimpleGeneratorWatcher(net.morimekta.providence.testing.generator.SimpleGeneratorWatcher) CompactFields(net.morimekta.test.providence.storage.jdbc.CompactFields) Clock(java.time.Clock) ProvidenceMatchers.equalToMessage(net.morimekta.providence.testing.ProvidenceMatchers.equalToMessage) ProvidenceJdbi.columnsFromAllFields(net.morimekta.providence.jdbi.v3.ProvidenceJdbi.columnsFromAllFields) Types(java.sql.Types) OptionalFields(net.morimekta.test.providence.storage.jdbc.OptionalFields) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 2 with BLOB_MESSAGE

use of net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BLOB_MESSAGE in project providence by morimekta.

the class MessageRowMapperTest method testDefaultMapping.

@Test
public void testDefaultMapping() {
    generator.setFillRate(1.0).setMaxCollectionItems(16).withGenerator(CompactFields.kDescriptor, g -> {
        g.setValueGenerator(CompactFields._Field.NAME, ctx -> ctx.getFairy().textProducer().latinWord());
        g.setValueGenerator(CompactFields._Field.LABEL, ctx -> ctx.getFairy().textProducer().word());
    }).withGenerator(NormalFields.kDescriptor, g -> {
        g.setValueGenerator(NormalFields._Field.NAME, ctx -> ctx.getFairy().textProducer().latinWord());
        g.setValueGenerator(NormalFields._Field.LABEL, ctx -> ctx.getFairy().textProducer().word());
    });
    OptionalFields expected = generator.generate(OptionalFields.kDescriptor).mutate().setId(1234).setTimestampS((int) clock.instant().getEpochSecond()).setTimestampMs(clock.instant().getEpochSecond() * 1000).build();
    OptionalFields empty = OptionalFields.builder().setId(2345).build();
    try (Handle handle = db.getDBI().open()) {
        handle.createStatement("INSERT INTO mappings.default_mappings (" + "  id, present, tiny, small, medium, large, real," + "  fib, name, data, compact," + "  timestamp_s, timestamp_ms," + "  binary_message, blob_message, other_message," + "  blob_data, base64_data, int_bool" + ") VALUES (" + "  :e.id," + "  :e.present," + "  :e.tiny," + "  :e.small," + "  :e.medium," + "  :e.large," + "  :e.real," + "  :e.fib," + "  :e.name," + "  :e.data," + "  :e.message," + "  :timestamp_s," + "  :e.timestamp_ms," + "  :e.binary_message," + "  :e.blob_message," + "  :e.clob_message," + "  :e.blob_data," + "  :e.base64_data," + "  :e.int_bool" + ")").bind("timestamp_s", ProvidenceJdbi.toField(expected, TIMESTAMP_S, Types.TIMESTAMP)).bindNamedArgumentFinder(ProvidenceJdbi.forMessage("e", expected, ProvidenceJdbi.withType(TIMESTAMP_MS, Types.TIMESTAMP), ProvidenceJdbi.withType(BINARY_MESSAGE, Types.BINARY), ProvidenceJdbi.withType(BLOB_MESSAGE, Types.BLOB), ProvidenceJdbi.withType(CLOB_MESSAGE, Types.CLOB), ProvidenceJdbi.withType(BLOB_DATA, Types.BLOB), ProvidenceJdbi.withType(BASE64_DATA, Types.VARCHAR))).execute();
        handle.createStatement("INSERT INTO mappings.default_mappings (" + "  id, present, tiny, small, medium, large, real," + "  fib, name, data, compact," + "  timestamp_s, timestamp_ms," + "  binary_message, blob_message, other_message," + "  blob_data, base64_data, int_bool" + ") VALUES (" + "  :id," + "  :present," + "  :tiny," + "  :small," + "  :medium," + "  :large," + "  :real," + "  :fib," + "  :name," + "  :data," + "  :message," + "  :timestamp_s," + "  :timestamp_ms," + "  :binary_message," + "  :blob_message," + "  :clob_message," + "  :blob_data," + "  :base64_data," + "  :int_bool" + ")").bind("timestamp_s", ProvidenceJdbi.toField(empty, TIMESTAMP_S, Types.TIMESTAMP)).bindNamedArgumentFinder(ProvidenceJdbi.forMessage(empty, ProvidenceJdbi.withType(TIMESTAMP_MS, Types.TIMESTAMP), ProvidenceJdbi.withType(BINARY_MESSAGE, Types.BINARY), ProvidenceJdbi.withType(BLOB_MESSAGE, Types.BLOB), ProvidenceJdbi.withType(CLOB_MESSAGE, Types.CLOB), ProvidenceJdbi.withType(BLOB_DATA, Types.BLOB), ProvidenceJdbi.withType(BASE64_DATA, Types.VARCHAR), ProvidenceJdbi.withType(INT_BOOL, Types.INTEGER))).execute();
        OptionalFields val = handle.createQuery("SELECT m.* FROM mappings.default_mappings m WHERE id = :id").bind("id", ProvidenceJdbi.toField(expected, ID)).map(ProvidenceJdbi.toMessage("default_mappings", OptionalFields.kDescriptor, ProvidenceJdbi.columnsFromAllFields(), ProvidenceJdbi.withColumn("compact", MESSAGE), ProvidenceJdbi.withColumn("other_message", CLOB_MESSAGE))).first();
        OptionalFields val2 = handle.createQuery("SELECT * FROM mappings.default_mappings WHERE id = :id").bind("id", ProvidenceJdbi.toField(empty, ID)).map(ProvidenceJdbi.toMessage(OptionalFields.kDescriptor, ProvidenceJdbi.columnsFromAllFields(), ProvidenceJdbi.withColumn("compact", MESSAGE), ProvidenceJdbi.withColumn("other_message", CLOB_MESSAGE))).first();
        assertThat(val, is(equalToMessage(expected)));
        assertThat(val2, is(equalToMessage(empty)));
    }
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) INT_BOOL(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.INT_BOOL) ID(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.ID) TIMESTAMP_MS(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.TIMESTAMP_MS) OptionalFields(net.morimekta.test.providence.storage.jdbc.OptionalFields) Test(org.junit.Test) BASE64_DATA(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BASE64_DATA) NormalFields(net.morimekta.test.providence.storage.jdbc.NormalFields) CLOB_MESSAGE(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.CLOB_MESSAGE) BINARY_MESSAGE(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BINARY_MESSAGE) BLOB_DATA(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BLOB_DATA) BLOB_MESSAGE(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BLOB_MESSAGE) Assert.assertThat(org.junit.Assert.assertThat) MESSAGE(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.MESSAGE) Rule(org.junit.Rule) Handle(org.skife.jdbi.v2.Handle) SimpleGeneratorWatcher(net.morimekta.providence.testing.generator.SimpleGeneratorWatcher) CompactFields(net.morimekta.test.providence.storage.jdbc.CompactFields) TIMESTAMP_S(net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.TIMESTAMP_S) Clock(java.time.Clock) ProvidenceMatchers.equalToMessage(net.morimekta.providence.testing.ProvidenceMatchers.equalToMessage) Types(java.sql.Types) OptionalFields(net.morimekta.test.providence.storage.jdbc.OptionalFields) Handle(org.skife.jdbi.v2.Handle) Test(org.junit.Test)

Aggregations

Types (java.sql.Types)2 Clock (java.time.Clock)2 ProvidenceMatchers.equalToMessage (net.morimekta.providence.testing.ProvidenceMatchers.equalToMessage)2 SimpleGeneratorWatcher (net.morimekta.providence.testing.generator.SimpleGeneratorWatcher)2 CompactFields (net.morimekta.test.providence.storage.jdbc.CompactFields)2 NormalFields (net.morimekta.test.providence.storage.jdbc.NormalFields)2 OptionalFields (net.morimekta.test.providence.storage.jdbc.OptionalFields)2 BASE64_DATA (net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BASE64_DATA)2 BINARY_MESSAGE (net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BINARY_MESSAGE)2 BLOB_DATA (net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BLOB_DATA)2 BLOB_MESSAGE (net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BLOB_MESSAGE)2 CLOB_MESSAGE (net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.CLOB_MESSAGE)2 ID (net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.ID)2 INT_BOOL (net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.INT_BOOL)2 MESSAGE (net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.MESSAGE)2 TIMESTAMP_MS (net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.TIMESTAMP_MS)2 TIMESTAMP_S (net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.TIMESTAMP_S)2 CoreMatchers.is (org.hamcrest.CoreMatchers.is)2 Assert.assertThat (org.junit.Assert.assertThat)2 Rule (org.junit.Rule)2