@Test public void tableReferencesAreCaseSensitiveForPutAndGet() { createTablesIgnoringException(); kvs.put(UPPER_UPPER, ImmutableMap.of(CELL, BYTE_ARRAY), 1); kvs.put(LOWER_LOWER, ImmutableMap.of(CELL, SECOND_BYTE_ARRAY), 1); assertThat(kvs.get(UPPER_UPPER, ImmutableMap.of(CELL, 2L)).get(CELL).getContents()).contains(BYTE_ARRAY); assertThat(kvs.get(LOWER_UPPER, ImmutableMap.of(CELL, 2L))).doesNotContainKey(CELL); assertThat(kvs.get(LOWER_LOWER, ImmutableMap.of(CELL, 2L)).get(CELL).getContents()).contains(SECOND_BYTE_ARRAY); }
@Test public void getMetadataReturnsResultFromNewMetadataCellOnConflict() { kvs.createTable(LOWER_UPPER, ORIGINAL_METADATA); insertGenericMetadataIntoLegacyCell(kvs, LOWER_UPPER); assertThat(kvs.getMetadataForTables().get(LOWER_UPPER)).contains(ORIGINAL_METADATA); assertThat(kvs.getMetadataForTable(LOWER_UPPER)).contains(ORIGINAL_METADATA); }
@Test public void tableCreationAppearsToSucceedButIsNoop() { kvs.createTable(UPPER_UPPER, AtlasDbConstants.GENERIC_TABLE_METADATA); kvs.createTable(LOWER_LOWER, AtlasDbConstants.GENERIC_TABLE_METADATA); kvs.put(UPPER_UPPER, ImmutableMap.of(CELL, BYTE_ARRAY), 1); assertThat(kvs.get(UPPER_UPPER, ImmutableMap.of(CELL, 2L)).get(CELL).getContents()).contains(BYTE_ARRAY); assertThatThrownBy(() -> kvs.get(LOWER_LOWER, ImmutableMap.of(CELL, 2L))) .isInstanceOf(RetryLimitReachedException.class); assertThatThrownBy(() -> kvs.put(LOWER_LOWER, ImmutableMap.of(CELL, SECOND_BYTE_ARRAY), 1)) .isInstanceOf(RetryLimitReachedException.class); }
@Test public void nonExistentTablesWithMetadataReturnMetadata() { insertMetadataIntoNewCell(LOWER_UPPER); assertThat(kvs.getMetadataForTable(LOWER_UPPER)).contains(AtlasDbConstants.GENERIC_TABLE_METADATA); }
@Test public void tableReferencesAreCaseSensitiveForDrop() { kvs.createTable(LOWER_UPPER, AtlasDbConstants.GENERIC_TABLE_METADATA); kvs.dropTable(LOWER_LOWER); assertThat(kvs.getAllTableNames()).containsExactly(LOWER_UPPER); assertThat(kvs.getMetadataForTable(LOWER_UPPER)).contains(AtlasDbConstants.GENERIC_TABLE_METADATA); }
/** * Verifies that the actual DeploymentResource's resource contains the given byte elements. * @param resource the given elements that should be contained in actual DeploymentResource's resource. * @return this assertion object. * @throws AssertionError if the actual DeploymentResource's resource does not contain all given byte elements. */ public S hasResource(byte... resource) { // check that actual DeploymentResource we want to make assertions on is not null. isNotNull(); // check that given byte varargs is not null. if (resource == null) failWithMessage("Expecting resource parameter not to be null."); // check with standard error message (use overridingErrorMessage before contains to set your own message). Assertions.assertThat(actual.getResource()).contains(resource); // return the current assertion for method chaining return myself; }
@Test @SuppressWarnings("unchecked") public void shouldWrappedMessageContainsMetadata() throws IOException { // when byte[] wrappedMessage = avroMessageContentWrapper.wrapContent(content, id, timestamp, avroUser.getSchema(), Collections.emptyMap()); // then GenericRecord messageWithMetadata = bytesToRecord(wrappedMessage, avroUser.getSchema()); Map<Utf8, Utf8> metadata = (Map<Utf8, Utf8>) messageWithMetadata.get(METADATA_MARKER); assertThat(metadata.get(METADATA_MESSAGE_ID_KEY).toString()).isEqualTo(id); assertThat(valueOf(metadata.get(METADATA_TIMESTAMP_KEY).toString())).isEqualTo(timestamp); assertThat(wrappedMessage).contains(content); }
/** * Verifies that the actual BonitaConfiguration's resourceContent contains the given byte elements. * @param resourceContent the given elements that should be contained in actual BonitaConfiguration's resourceContent. * @return this assertion object. * @throws AssertionError if the actual BonitaConfiguration's resourceContent does not contain all given byte elements. */ public BonitaConfigurationAssert hasResourceContent(byte... resourceContent) { // check that actual BonitaConfiguration we want to make assertions on is not null. isNotNull(); // check that given byte varargs is not null. if (resourceContent == null) failWithMessage("Expecting resourceContent parameter not to be null."); // check with standard error message (use overridingErrorMessage before contains to set your own message). Assertions.assertThat(actual.getResourceContent()).contains(resourceContent); // return the current assertion for method chaining return this; }
@Test public void shouldWrapAndUnwrapAvroMessageWithMetadata() throws IOException { // when byte [] wrappedMessage = avroMessageContentWrapper.wrapContent(content, id, timestamp, avroUser.getSchema(), Collections.emptyMap()); UnwrappedMessageContent unwrappedMessageContent = avroMessageContentWrapper.unwrapContent(wrappedMessage, avroUser.getCompiledSchema()); // then assertThat(unwrappedMessageContent.getMessageMetadata().getId()).isEqualTo(id); assertThat(unwrappedMessageContent.getMessageMetadata().getTimestamp()).isEqualTo(timestamp); assertThat(unwrappedMessageContent.getContent()).contains(content); }
public void shouldUnwrapMessageWrappedWithSchemaAtVersion(MessageContentWrapper wrapper, int schemaVersion, boolean wrapWithSchemaVersionAwarePayload, boolean unwrapWithSchemaVersionAwarePayload, int missedSchemaVersionInPayload, int errorsForPayloadWithSchemaVersion, int errorsForAnySchemaVersion, int errorsForAnyOnlineSchemaVersion) { // given SchemaVersion version = SchemaVersion.valueOf(schemaVersion); Topic topicToWrap = createTopic("group", "topic", wrapWithSchemaVersionAwarePayload); Topic topicToUnwrap = createTopic("group", "topic", unwrapWithSchemaVersionAwarePayload); CompiledSchema<Schema> schema = schemaRepository.getKnownAvroSchemaVersion(topicToWrap, version); AvroUser user = new AvroUser(schema, "Bob", 15, "blue"); byte[] wrapped = wrapper.wrapAvro(user.asBytes(), "uniqueId", 1234, topicToWrap, schema, new HashedMap<>()); // when UnwrappedMessageContent unwrappedMessageContent = wrapper.unwrapAvro(wrapped, topicToUnwrap); // then assertThat(unwrappedMessageContent.getContent()).contains(user.asBytes()); assertThat(unwrappedMessageContent.getSchema().get().getVersion()).isEqualTo(version); assertThat(unwrappedMessageContent.getMessageMetadata().getId()).isEqualTo("uniqueId"); assertThat(unwrappedMessageContent.getMessageMetadata().getTimestamp()).isEqualTo(1234); assertThat(metrics.missedSchemaVersionInPayload().getCount()).isEqualTo(missedSchemaVersionInPayload); assertThat(metrics.errorsForSchemaVersionAwarePayload().getCount()).isEqualTo(errorsForPayloadWithSchemaVersion); assertThat(metrics.errorsForAnySchemaVersion().getCount()).isEqualTo(errorsForAnySchemaVersion); assertThat(metrics.errorsForAnyOnlineSchemaVersion().getCount()).isEqualTo(errorsForAnyOnlineSchemaVersion); }
@Test public void shouldUnwrapAvroMessageAndSetEmptyMessageIdWhenNotGivenInMetadata() throws Throwable { // given byte [] wrappedMessage = wrapContentWithoutMessageIdInMetadata(content, avroUser.getSchema()); //when UnwrappedMessageContent unwrappedMessage = avroMessageContentWrapper.unwrapContent(wrappedMessage, avroUser.getCompiledSchema()); // then assertThat(unwrappedMessage.getMessageMetadata().getId()).isEmpty(); assertThat(unwrappedMessage.getMessageMetadata().getTimestamp()).isNotNull(); assertThat(unwrappedMessage.getContent()).contains(content); }