Search in sources :

Example 1 with DivolteSchema

use of io.divolte.server.DivolteSchema in project divolte-collector by divolte.

the class SchemaRegistryTest method testConfluentSinkCorrectlyAssociatedWithSchemaId.

@Test
public void testConfluentSinkCorrectlyAssociatedWithSchemaId() {
    final ValidatedConfiguration vc = new ValidatedConfiguration(() -> ConfigFactory.parseResources("schema-registry-with-confluent.conf"));
    final SchemaRegistry registry = new SchemaRegistry(vc);
    final DivolteSchema schema = registry.getSchemaBySinkName("kafka");
    assertEquals(schema.confluentId, Optional.of(12345));
}
Also used : SchemaRegistry(io.divolte.server.SchemaRegistry) DivolteSchema(io.divolte.server.DivolteSchema) Test(org.junit.Test)

Example 2 with DivolteSchema

use of io.divolte.server.DivolteSchema in project divolte-collector by divolte.

the class GoogleCloudPubSubFlusher method schemaFingerprint.

private static String schemaFingerprint(final DivolteSchema schema) {
    final Schema avroSchema = schema.avroSchema;
    final byte[] fingerprint;
    // SHA-256 is on the list of mandatory JCE algorithms, so this shouldn't be an issue.
    try {
        fingerprint = SchemaNormalization.parsingFingerprint("SHA-256", avroSchema);
    } catch (final NoSuchAlgorithmException e) {
        throw new RuntimeException("Cannot calculate schema fingerprint; missing SHA-256 digest algorithm", e);
    }
    return FINGERPRINT_ENCODER.encodeToString(fingerprint);
}
Also used : Schema(org.apache.avro.Schema) DivolteSchema(io.divolte.server.DivolteSchema) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 3 with DivolteSchema

use of io.divolte.server.DivolteSchema in project divolte-collector by divolte.

the class GoogleCloudPubSubFlusherTest method processSingleMessage.

private void processSingleMessage(final Optional<Integer> confluentId) {
    final Publisher publisher = mockPublisher.orElseThrow(IllegalStateException::new);
    // Process a single message.
    final DivolteSchema schema = new DivolteSchema(MINIMAL_SCHEMA, confluentId);
    final GoogleCloudPubSubFlusher flusher = new GoogleCloudPubSubFlusher(publisher, schema);
    if (ItemProcessor.ProcessingDirective.PAUSE == flusher.process(itemFromAvroRecordBuffer(generateMessage()))) {
        flusher.heartbeat();
    }
}
Also used : Publisher(com.google.cloud.pubsub.v1.Publisher) DivolteSchema(io.divolte.server.DivolteSchema)

Example 4 with DivolteSchema

use of io.divolte.server.DivolteSchema in project divolte-collector by divolte.

the class GoogleCloudPubSubFlusherTest method testMessageBatchSentToPublisher.

@Test
public void testMessageBatchSentToPublisher() {
    final Publisher publisher = mockPublisher.orElseThrow(IllegalStateException::new);
    // Process a bunch of messages.
    final DivolteSchema schema = new DivolteSchema(MINIMAL_SCHEMA, Optional.empty());
    final GoogleCloudPubSubFlusher flusher = new GoogleCloudPubSubFlusher(publisher, schema);
    final Queue<Item<AvroRecordBuffer>> items = Stream.generate(this::generateMessage).limit(10).map(this::itemFromAvroRecordBuffer).collect(Collectors.toCollection(() -> new ArrayBlockingQueue<>(10)));
    flusher.process(items);
    // Check the messages were all forwarded to the publisher.
    verify(publisher, times(10)).publish(any(PubsubMessage.class));
    verifyNoMoreInteractions(publisher);
}
Also used : Item(io.divolte.server.processing.Item) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Publisher(com.google.cloud.pubsub.v1.Publisher) PubsubMessage(com.google.pubsub.v1.PubsubMessage) DivolteSchema(io.divolte.server.DivolteSchema) Test(org.junit.Test)

Aggregations

DivolteSchema (io.divolte.server.DivolteSchema)4 Publisher (com.google.cloud.pubsub.v1.Publisher)2 Test (org.junit.Test)2 PubsubMessage (com.google.pubsub.v1.PubsubMessage)1 SchemaRegistry (io.divolte.server.SchemaRegistry)1 Item (io.divolte.server.processing.Item)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 Schema (org.apache.avro.Schema)1