From 0683fb06a027cb1bb4ee26975610c58e3a766858 Mon Sep 17 00:00:00 2001 From: zhangliang Date: Mon, 16 Sep 2024 14:47:25 +0800 Subject: [PATCH] Add more test cases on QualifiedDataSourceDispatchEventBuilder --- ...iedDataSourceDispatchEventBuilderTest.java | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/QualifiedDataSourceDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/QualifiedDataSourceDispatchEventBuilderTest.java index 8245f3efe71d3..e227f233fec3d 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/QualifiedDataSourceDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/QualifiedDataSourceDispatchEventBuilderTest.java @@ -36,30 +36,29 @@ class QualifiedDataSourceDispatchEventBuilderTest { private final QualifiedDataSourceDispatchEventBuilder builder = new QualifiedDataSourceDispatchEventBuilder(); @Test - void assertCreateEnabledQualifiedDataSourceChangedEvent() { - Optional actual = builder.build(new DataChangedEvent("/nodes/qualified_data_sources/replica_query_db.readwrite_ds.replica_ds_0", "state: ENABLED\n", Type.ADDED)); - assertTrue(actual.isPresent()); - QualifiedDataSourceStateEvent actualEvent = (QualifiedDataSourceStateEvent) actual.get(); - assertThat(actualEvent.getQualifiedDataSource().getDatabaseName(), is("replica_query_db")); - assertThat(actualEvent.getQualifiedDataSource().getGroupName(), is("readwrite_ds")); - assertThat(actualEvent.getQualifiedDataSource().getDataSourceName(), is("replica_ds_0")); - assertThat(actualEvent.getStatus().getState(), is(DataSourceState.ENABLED)); + void assertGetSubscribedKey() { + assertThat(builder.getSubscribedKey(), is("/nodes/qualified_data_sources")); } @Test - void assertCreateDisabledQualifiedDataSourceChangedEvent() { - Optional actual = builder.build(new DataChangedEvent("/nodes/qualified_data_sources/replica_query_db.readwrite_ds.replica_ds_0", "state: DISABLED\n", Type.DELETED)); + void assertBuildQualifiedDataSourceStateEvent() { + Optional actual = builder.build(new DataChangedEvent("/nodes/qualified_data_sources/foo_db.foo_group.foo_ds", "state: ENABLED", Type.ADDED)); assertTrue(actual.isPresent()); - QualifiedDataSourceStateEvent actualEvent = (QualifiedDataSourceStateEvent) actual.get(); - assertThat(actualEvent.getQualifiedDataSource().getDatabaseName(), is("replica_query_db")); - assertThat(actualEvent.getQualifiedDataSource().getGroupName(), is("readwrite_ds")); - assertThat(actualEvent.getQualifiedDataSource().getDataSourceName(), is("replica_ds_0")); - assertThat(actualEvent.getStatus().getState(), is(DataSourceState.DISABLED)); + assertThat(((QualifiedDataSourceStateEvent) actual.get()).getQualifiedDataSource().getDatabaseName(), is("foo_db")); + assertThat(((QualifiedDataSourceStateEvent) actual.get()).getQualifiedDataSource().getGroupName(), is("foo_group")); + assertThat(((QualifiedDataSourceStateEvent) actual.get()).getQualifiedDataSource().getDataSourceName(), is("foo_ds")); + assertThat(((QualifiedDataSourceStateEvent) actual.get()).getStatus().getState(), is(DataSourceState.ENABLED)); + } + + @Test + void assertBuildWithEmptyValue() { + Optional actual = builder.build(new DataChangedEvent("/nodes/qualified_data_sources/foo_db.foo_group.foo_ds", "", Type.ADDED)); + assertFalse(actual.isPresent()); } @Test - void assertCreateEmptyEvent() { - Optional actual = builder.build(new DataChangedEvent("/nodes/qualified_data_sources/replica_query_db.readwrite_ds.replica_ds_0", "", Type.ADDED)); + void assertBuildWithoutQualifiedDataSource() { + Optional actual = builder.build(new DataChangedEvent("/nodes/qualified_data_sources", "state: DISABLED", Type.ADDED)); assertFalse(actual.isPresent()); } }