-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-7833: Add missing test #8847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| import org.apache.kafka.streams.errors.TopologyException; | ||
| import org.apache.kafka.streams.processor.StateStore; | ||
| import org.apache.kafka.streams.processor.TopicNameExtractor; | ||
| import org.apache.kafka.streams.state.KeyValueStore; | ||
| import org.apache.kafka.streams.state.StoreBuilder; | ||
| import org.apache.kafka.streams.state.Stores; | ||
| import org.apache.kafka.test.MockKeyValueStoreBuilder; | ||
|
|
@@ -62,7 +63,7 @@ public class InternalTopologyBuilderTest { | |
|
|
||
| private final Serde<String> stringSerde = Serdes.String(); | ||
| private final InternalTopologyBuilder builder = new InternalTopologyBuilder(); | ||
| private final StoreBuilder<?> storeBuilder = new MockKeyValueStoreBuilder("store", false); | ||
| private final StoreBuilder<?> storeBuilder = new MockKeyValueStoreBuilder("testStore", false); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just renaming the store to make the error message in the tests easier to read. |
||
|
|
||
| @Test | ||
| public void shouldAddSourceWithOffsetReset() { | ||
|
|
@@ -372,48 +373,112 @@ public void testAddStateStoreWithSink() { | |
|
|
||
| @Test | ||
| public void shouldNotAllowToAddStoresWithSameName() { | ||
| final StoreBuilder<KeyValueStore<Object, Object>> otherBuilder = | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just refactoring:
|
||
| new MockKeyValueStoreBuilder("testStore", false); | ||
|
|
||
| builder.addStateStore(storeBuilder); | ||
| final StoreBuilder otherBuilder = new MockKeyValueStoreBuilder("store", false); | ||
| try { | ||
| builder.addStateStore(otherBuilder); | ||
| fail("Should throw TopologyException with store name conflict"); | ||
| } catch (final TopologyException expected) { /* ok */ } | ||
|
|
||
| final TopologyException exception = assertThrows( | ||
| TopologyException.class, | ||
| () -> builder.addStateStore(otherBuilder) | ||
| ); | ||
|
|
||
| assertThat( | ||
| exception.getMessage(), | ||
| equalTo("Invalid topology: A different StateStore has already been added with the name testStore") | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotAllowToAddStoresWithSameNameWhenFirstStoreIsGlobal() { | ||
| final StoreBuilder storeBuilder = new MockKeyValueStoreBuilder("store", false).withLoggingDisabled(); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above |
||
| final StoreBuilder<KeyValueStore<Object, Object>> globalBuilder = | ||
| new MockKeyValueStoreBuilder("testStore", false).withLoggingDisabled(); | ||
|
|
||
| builder.addGlobalStore( | ||
| storeBuilder, | ||
| globalBuilder, | ||
| "global-store", | ||
| null, | ||
| null, | ||
| null, | ||
| "global-topic", | ||
| "global-processor", | ||
| new MockProcessorSupplier<>() | ||
| ); | ||
|
|
||
| final TopologyException exception = assertThrows( | ||
| TopologyException.class, | ||
| () -> builder.addStateStore(storeBuilder) | ||
| ); | ||
|
|
||
| assertThat( | ||
| exception.getMessage(), | ||
| equalTo("Invalid topology: A different GlobalStateStore has already been added with the name testStore") | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotAllowToAddStoresWithSameNameWhenSecondStoreIsGlobal() { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above (the diff is just weird... this is an existing test; cf. below) |
||
| final StoreBuilder<KeyValueStore<Object, Object>> globalBuilder = | ||
| new MockKeyValueStoreBuilder("testStore", false).withLoggingDisabled(); | ||
|
|
||
| builder.addStateStore(storeBuilder); | ||
|
|
||
| final TopologyException exception = assertThrows( | ||
| TopologyException.class, | ||
| () -> builder.addGlobalStore( | ||
| globalBuilder, | ||
| "global-store", | ||
| null, | ||
| null, | ||
| null, | ||
| "global-topic", | ||
| "global-processor", | ||
| new MockProcessorSupplier<>()); | ||
| try { | ||
| builder.addStateStore(storeBuilder); | ||
| fail("Should throw TopologyException with store name conflict"); | ||
| } catch (final TopologyException expected) { /* ok */ } | ||
| new MockProcessorSupplier<>() | ||
| ) | ||
| ); | ||
|
|
||
| assertThat( | ||
| exception.getMessage(), | ||
| equalTo("Invalid topology: A different StateStore has already been added with the name testStore") | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotAllowToAddStoresWithSameNameWhenSecondStoreIsGlobal() { | ||
| final StoreBuilder storeBuilder = new MockKeyValueStoreBuilder("store", false).withLoggingDisabled(); | ||
| builder.addStateStore(storeBuilder); | ||
| try { | ||
| builder.addGlobalStore( | ||
| storeBuilder, | ||
| "global-store", | ||
| null, | ||
| null, | ||
| null, | ||
| "global-topic", | ||
| "global-processor", | ||
| new MockProcessorSupplier<>()); | ||
| fail("Should throw TopologyException with store name conflict"); | ||
| } catch (final TopologyException expected) { /* ok */ } | ||
| public void shouldNotAllowToAddGlobalStoresWithSameName() { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the missing test case. |
||
| final StoreBuilder<KeyValueStore<Object, Object>> firstGlobalBuilder = | ||
| new MockKeyValueStoreBuilder("testStore", false).withLoggingDisabled(); | ||
| final StoreBuilder<KeyValueStore<Object, Object>> secondGlobalBuilder = | ||
| new MockKeyValueStoreBuilder("testStore", false).withLoggingDisabled(); | ||
|
|
||
| builder.addGlobalStore( | ||
| firstGlobalBuilder, | ||
| "global-store", | ||
| null, | ||
| null, | ||
| null, | ||
| "global-topic", | ||
| "global-processor", | ||
| new MockProcessorSupplier<>() | ||
| ); | ||
|
|
||
| final TopologyException exception = assertThrows( | ||
| TopologyException.class, | ||
| () -> builder.addGlobalStore( | ||
| secondGlobalBuilder, | ||
| "global-store-2", | ||
| null, | ||
| null, | ||
| null, | ||
| "global-topic", | ||
| "global-processor-2", | ||
| new MockProcessorSupplier<>() | ||
| ) | ||
| ); | ||
|
|
||
| assertThat( | ||
| exception.getMessage(), | ||
| equalTo("Invalid topology: A different GlobalStateStore has already been added with the name testStore") | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -682,7 +747,7 @@ public void shouldAssociateStateStoreNameWhenStateStoreSupplierIsInternal() { | |
| builder.addStateStore(storeBuilder, "processor"); | ||
| final Map<String, List<String>> stateStoreNameToSourceTopic = builder.stateStoreNameToSourceTopics(); | ||
| assertEquals(1, stateStoreNameToSourceTopic.size()); | ||
| assertEquals(Collections.singletonList("topic"), stateStoreNameToSourceTopic.get("store")); | ||
| assertEquals(Collections.singletonList("topic"), stateStoreNameToSourceTopic.get("testStore")); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -692,7 +757,7 @@ public void shouldAssociateStateStoreNameWhenStateStoreSupplierIsExternal() { | |
| builder.addStateStore(storeBuilder, "processor"); | ||
| final Map<String, List<String>> stateStoreNameToSourceTopic = builder.stateStoreNameToSourceTopics(); | ||
| assertEquals(1, stateStoreNameToSourceTopic.size()); | ||
| assertEquals(Collections.singletonList("topic"), stateStoreNameToSourceTopic.get("store")); | ||
| assertEquals(Collections.singletonList("topic"), stateStoreNameToSourceTopic.get("testStore")); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -704,7 +769,7 @@ public void shouldCorrectlyMapStateStoreToInternalTopics() { | |
| builder.addStateStore(storeBuilder, "processor"); | ||
| final Map<String, List<String>> stateStoreNameToSourceTopic = builder.stateStoreNameToSourceTopics(); | ||
| assertEquals(1, stateStoreNameToSourceTopic.size()); | ||
| assertEquals(Collections.singletonList("appId-internal-topic"), stateStoreNameToSourceTopic.get("store")); | ||
| assertEquals(Collections.singletonList("appId-internal-topic"), stateStoreNameToSourceTopic.get("testStore")); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -754,11 +819,11 @@ public void shouldAddInternalTopicConfigForNonWindowStores() { | |
| builder.buildTopology(); | ||
| final Map<Integer, InternalTopologyBuilder.TopicsInfo> topicGroups = builder.topicGroups(); | ||
| final InternalTopologyBuilder.TopicsInfo topicsInfo = topicGroups.values().iterator().next(); | ||
| final InternalTopicConfig topicConfig = topicsInfo.stateChangelogTopics.get("appId-store-changelog"); | ||
| final InternalTopicConfig topicConfig = topicsInfo.stateChangelogTopics.get("appId-testStore-changelog"); | ||
| final Map<String, String> properties = topicConfig.getProperties(Collections.emptyMap(), 10000); | ||
| assertEquals(2, properties.size()); | ||
| assertEquals(TopicConfig.CLEANUP_POLICY_COMPACT, properties.get(TopicConfig.CLEANUP_POLICY_CONFIG)); | ||
| assertEquals("appId-store-changelog", topicConfig.name()); | ||
| assertEquals("appId-testStore-changelog", topicConfig.name()); | ||
| assertTrue(topicConfig instanceof UnwindowedChangelogTopicConfig); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor improvement for the error message