Search in sources :

Example 1 with TYPE

use of org.infinispan.cloudevents.impl.StructuredEventBuilder.TYPE in project infinispan by infinispan.

the class CacheEntryCloudEventsTest method assertEntryEventSent.

private void assertEntryEventSent(Object key, Object value, TestWriteOperation op) {
    byte[] expectedKeyBytes = getKeyBytes(key);
    byte[] expectedValueBytes = getValueBytes(value);
    String type = translateType(op);
    Optional<ProducerRecord<byte[], byte[]>> record = mockSender.getProducer().history().stream().filter(r -> Arrays.equals(r.key(), expectedKeyBytes)).findFirst();
    assertTrue(record.isPresent());
    byte[] eventBytes = record.get().value();
    Json json = Json.read(new String(eventBytes));
    assertEquals("1.0", json.at(SPECVERSION).asString());
    assertEquals(type, json.at(TYPE).asString());
    String source = json.at(SOURCE).asString();
    assertTrue(source.startsWith("/infinispan"));
    assertTrue(source.endsWith("/" + CACHE_NAME));
    Instant.parse(json.at(TIME).asString());
    boolean keyIsBase64 = json.at(INFINISPAN_SUBJECT_ISBASE64, false).asBoolean();
    assertEquals(expectedContentType(keyIsBase64).toString(), json.at(INFINISPAN_SUBJECT_CONTENTTYPE, APPLICATION_JSON_TYPE).asString());
    String subject = json.at(SUBJECT).asString();
    byte[] keyBytes = keyIsBase64 ? Base64.getDecoder().decode(subject) : subject.getBytes(StandardCharsets.UTF_8);
    assertEquals(expectedKeyBytes, keyBytes);
    String data = json.at(DATA).asString();
    boolean valueIsBase64 = json.at(INFINISPAN_DATA_ISBASE64, false).asBoolean();
    assertEquals(expectedContentType(valueIsBase64).toString(), json.at(DATACONTENTTYPE, APPLICATION_JSON_TYPE).asString());
    byte[] valueBytes = valueIsBase64 ? Base64.getDecoder().decode(data) : data.getBytes(StandardCharsets.UTF_8);
    assertEquals(expectedValueBytes, valueBytes);
}
Also used : Arrays(java.util.Arrays) TestGlobalConfigurationBuilder(org.infinispan.commands.module.TestGlobalConfigurationBuilder) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test) Cache(org.infinispan.Cache) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) AdvancedCache(org.infinispan.AdvancedCache) DATACONTENTTYPE(org.infinispan.cloudevents.impl.StructuredEventBuilder.DATACONTENTTYPE) APPLICATION_OBJECT(org.infinispan.commons.dataconversion.MediaType.APPLICATION_OBJECT) Map(java.util.Map) TestingUtil(org.infinispan.test.TestingUtil) MagicKey(org.infinispan.distribution.MagicKey) TestDataSCI(org.infinispan.test.TestDataSCI) KafkaEventSender(org.infinispan.cloudevents.impl.KafkaEventSender) Instant(java.time.Instant) StandardCharsets(java.nio.charset.StandardCharsets) INFINISPAN_SUBJECT_ISBASE64(org.infinispan.cloudevents.impl.StructuredEventBuilder.INFINISPAN_SUBJECT_ISBASE64) Base64(java.util.Base64) CompletionStage(java.util.concurrent.CompletionStage) Flag(org.infinispan.context.Flag) Optional(java.util.Optional) DataConversion(org.infinispan.encoding.DataConversion) INFINISPAN_SUBJECT_CONTENTTYPE(org.infinispan.cloudevents.impl.StructuredEventBuilder.INFINISPAN_SUBJECT_CONTENTTYPE) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) DataProvider(org.testng.annotations.DataProvider) TYPE(org.infinispan.cloudevents.impl.StructuredEventBuilder.TYPE) PrivateGlobalConfigurationBuilder(org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) INFINISPAN_DATA_ISBASE64(org.infinispan.cloudevents.impl.StructuredEventBuilder.INFINISPAN_DATA_ISBASE64) LinkedHashMap(java.util.LinkedHashMap) APPLICATION_UNKNOWN(org.infinispan.commons.dataconversion.MediaType.APPLICATION_UNKNOWN) MediaType(org.infinispan.commons.dataconversion.MediaType) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) DATA(org.infinispan.cloudevents.impl.StructuredEventBuilder.DATA) Address(org.infinispan.remoting.transport.Address) APPLICATION_PROTOSTREAM(org.infinispan.commons.dataconversion.MediaType.APPLICATION_PROTOSTREAM) StorageType(org.infinispan.configuration.cache.StorageType) APPLICATION_JSON(org.infinispan.commons.dataconversion.MediaType.APPLICATION_JSON) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest) TIME(org.infinispan.cloudevents.impl.StructuredEventBuilder.TIME) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) SUBJECT(org.infinispan.cloudevents.impl.StructuredEventBuilder.SUBJECT) AssertJUnit.assertFalse(org.testng.AssertJUnit.assertFalse) SOURCE(org.infinispan.cloudevents.impl.StructuredEventBuilder.SOURCE) SPECVERSION(org.infinispan.cloudevents.impl.StructuredEventBuilder.SPECVERSION) Json(org.infinispan.commons.dataconversion.internal.Json) ExecutionException(java.util.concurrent.ExecutionException) APPLICATION_JSON_TYPE(org.infinispan.commons.dataconversion.MediaType.APPLICATION_JSON_TYPE) CacheMode(org.infinispan.configuration.cache.CacheMode) TestWriteOperation(org.infinispan.test.op.TestWriteOperation) CloudEventsGlobalConfigurationBuilder(org.infinispan.cloudevents.configuration.CloudEventsGlobalConfigurationBuilder) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) Json(org.infinispan.commons.dataconversion.internal.Json)

Aggregations

StandardCharsets (java.nio.charset.StandardCharsets)1 Instant (java.time.Instant)1 Arrays (java.util.Arrays)1 Base64 (java.util.Base64)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 ExecutionException (java.util.concurrent.ExecutionException)1 SECONDS (java.util.concurrent.TimeUnit.SECONDS)1 TimeoutException (java.util.concurrent.TimeoutException)1 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)1 AdvancedCache (org.infinispan.AdvancedCache)1 Cache (org.infinispan.Cache)1 CloudEventsGlobalConfigurationBuilder (org.infinispan.cloudevents.configuration.CloudEventsGlobalConfigurationBuilder)1 KafkaEventSender (org.infinispan.cloudevents.impl.KafkaEventSender)1 DATA (org.infinispan.cloudevents.impl.StructuredEventBuilder.DATA)1 DATACONTENTTYPE (org.infinispan.cloudevents.impl.StructuredEventBuilder.DATACONTENTTYPE)1 INFINISPAN_DATA_ISBASE64 (org.infinispan.cloudevents.impl.StructuredEventBuilder.INFINISPAN_DATA_ISBASE64)1