-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cases on CountResultRowBuilder's impl (#33472)
- Loading branch information
Showing
8 changed files
with
438 additions
and
2 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...he/shardingsphere/broadcast/distsql/handler/query/BroadcastCountResultRowBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.broadcast.distsql.handler.query; | ||
|
||
import org.apache.shardingsphere.broadcast.rule.BroadcastRule; | ||
import org.apache.shardingsphere.distsql.handler.executor.rql.rule.CountResultRowBuilder; | ||
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; | ||
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class BroadcastCountResultRowBuilderTest { | ||
|
||
@SuppressWarnings("unchecked") | ||
private final CountResultRowBuilder<BroadcastRule> builder = TypedSPILoader.getService(CountResultRowBuilder.class, "BROADCAST"); | ||
|
||
@Test | ||
void assertGenerateRows() { | ||
List<LocalDataQueryResultRow> actual = new ArrayList<>(builder.generateRows(mockRule(), "foo_db")); | ||
assertThat(actual.size(), is(1)); | ||
assertThat(actual.get(0).getCell(1), is("broadcast_table")); | ||
assertThat(actual.get(0).getCell(2), is("foo_db")); | ||
assertThat(actual.get(0).getCell(3), is("1")); | ||
} | ||
|
||
private BroadcastRule mockRule() { | ||
BroadcastRule result = mock(BroadcastRule.class, RETURNS_DEEP_STUBS); | ||
when(result.getConfiguration().getTables().size()).thenReturn(1); | ||
return result; | ||
} | ||
|
||
@Test | ||
void assertGetRuleClass() { | ||
assertThat(builder.getRuleClass(), is(BroadcastRule.class)); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...apache/shardingsphere/encrypt/distsql/handler/query/EncryptCountResultRowBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.encrypt.distsql.handler.query; | ||
|
||
import org.apache.shardingsphere.distsql.handler.executor.rql.rule.CountResultRowBuilder; | ||
import org.apache.shardingsphere.encrypt.rule.EncryptRule; | ||
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; | ||
import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; | ||
import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; | ||
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class EncryptCountResultRowBuilderTest { | ||
|
||
@SuppressWarnings("unchecked") | ||
private final CountResultRowBuilder<EncryptRule> builder = TypedSPILoader.getService(CountResultRowBuilder.class, "ENCRYPT"); | ||
|
||
@Test | ||
void assertGenerateRows() { | ||
List<LocalDataQueryResultRow> actual = new ArrayList<>(builder.generateRows(mockRule(), "foo_db")); | ||
assertThat(actual.size(), is(1)); | ||
assertThat(actual.get(0).getCell(1), is("encrypt")); | ||
assertThat(actual.get(0).getCell(2), is("foo_db")); | ||
assertThat(actual.get(0).getCell(3), is("1")); | ||
} | ||
|
||
private EncryptRule mockRule() { | ||
TableMapperRuleAttribute tableMapperRuleAttribute = mock(TableMapperRuleAttribute.class, RETURNS_DEEP_STUBS); | ||
when(tableMapperRuleAttribute.getLogicTableNames().size()).thenReturn(1); | ||
EncryptRule result = mock(EncryptRule.class); | ||
when(result.getAttributes()).thenReturn(new RuleAttributes(tableMapperRuleAttribute)); | ||
return result; | ||
} | ||
|
||
@Test | ||
void assertGetRuleClass() { | ||
assertThat(builder.getRuleClass(), is(EncryptRule.class)); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...a/org/apache/shardingsphere/mask/distsql/handler/query/MaskCountResultRowBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.mask.distsql.handler.query; | ||
|
||
import org.apache.shardingsphere.distsql.handler.executor.rql.rule.CountResultRowBuilder; | ||
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; | ||
import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; | ||
import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; | ||
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; | ||
import org.apache.shardingsphere.mask.rule.MaskRule; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class MaskCountResultRowBuilderTest { | ||
|
||
@SuppressWarnings("unchecked") | ||
private final CountResultRowBuilder<MaskRule> builder = TypedSPILoader.getService(CountResultRowBuilder.class, "MASK"); | ||
|
||
@Test | ||
void assertGenerateRows() { | ||
List<LocalDataQueryResultRow> actual = new ArrayList<>(builder.generateRows(mockRule(), "foo_db")); | ||
assertThat(actual.size(), is(1)); | ||
assertThat(actual.get(0).getCell(1), is("mask")); | ||
assertThat(actual.get(0).getCell(2), is("foo_db")); | ||
assertThat(actual.get(0).getCell(3), is("1")); | ||
} | ||
|
||
private MaskRule mockRule() { | ||
TableMapperRuleAttribute tableMapperRuleAttribute = mock(TableMapperRuleAttribute.class, RETURNS_DEEP_STUBS); | ||
when(tableMapperRuleAttribute.getLogicTableNames().size()).thenReturn(1); | ||
MaskRule result = mock(MaskRule.class); | ||
when(result.getAttributes()).thenReturn(new RuleAttributes(tableMapperRuleAttribute)); | ||
return result; | ||
} | ||
|
||
@Test | ||
void assertGetRuleClass() { | ||
assertThat(builder.getRuleClass(), is(MaskRule.class)); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...readwritesplitting/distsql/handler/query/ReadwriteSplittingCountResultRowBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.readwritesplitting.distsql.handler.query; | ||
|
||
import org.apache.shardingsphere.distsql.handler.executor.rql.rule.CountResultRowBuilder; | ||
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; | ||
import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; | ||
import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; | ||
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; | ||
import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class ReadwriteSplittingCountResultRowBuilderTest { | ||
|
||
@SuppressWarnings("unchecked") | ||
private final CountResultRowBuilder<ReadwriteSplittingRule> builder = TypedSPILoader.getService(CountResultRowBuilder.class, "READWRITE_SPLITTING"); | ||
|
||
@Test | ||
void assertGenerateRows() { | ||
List<LocalDataQueryResultRow> actual = new ArrayList<>(builder.generateRows(mockRule(), "foo_db")); | ||
assertThat(actual.size(), is(1)); | ||
assertThat(actual.get(0).getCell(1), is("readwrite_splitting")); | ||
assertThat(actual.get(0).getCell(2), is("foo_db")); | ||
assertThat(actual.get(0).getCell(3), is("1")); | ||
} | ||
|
||
private ReadwriteSplittingRule mockRule() { | ||
DataSourceMapperRuleAttribute dataSourceMapperRuleAttribute = mock(DataSourceMapperRuleAttribute.class, RETURNS_DEEP_STUBS); | ||
when(dataSourceMapperRuleAttribute.getDataSourceMapper().size()).thenReturn(1); | ||
ReadwriteSplittingRule result = mock(ReadwriteSplittingRule.class); | ||
when(result.getAttributes()).thenReturn(new RuleAttributes(dataSourceMapperRuleAttribute)); | ||
return result; | ||
} | ||
|
||
@Test | ||
void assertGetRuleClass() { | ||
assertThat(builder.getRuleClass(), is(ReadwriteSplittingRule.class)); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...g/apache/shardingsphere/shadow/distsql/handler/query/ShadowCountResultRowBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.shadow.distsql.handler.query; | ||
|
||
import org.apache.shardingsphere.distsql.handler.executor.rql.rule.CountResultRowBuilder; | ||
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; | ||
import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; | ||
import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; | ||
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; | ||
import org.apache.shardingsphere.shadow.rule.ShadowRule; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class ShadowCountResultRowBuilderTest { | ||
|
||
@SuppressWarnings("unchecked") | ||
private final CountResultRowBuilder<ShadowRule> builder = TypedSPILoader.getService(CountResultRowBuilder.class, "SHADOW"); | ||
|
||
@Test | ||
void assertGenerateRows() { | ||
List<LocalDataQueryResultRow> actual = new ArrayList<>(builder.generateRows(mockRule(), "foo_db")); | ||
assertThat(actual.size(), is(1)); | ||
assertThat(actual.get(0).getCell(1), is("shadow")); | ||
assertThat(actual.get(0).getCell(2), is("foo_db")); | ||
assertThat(actual.get(0).getCell(3), is("1")); | ||
} | ||
|
||
private ShadowRule mockRule() { | ||
DataSourceMapperRuleAttribute dataSourceMapperRuleAttribute = mock(DataSourceMapperRuleAttribute.class, RETURNS_DEEP_STUBS); | ||
when(dataSourceMapperRuleAttribute.getDataSourceMapper().size()).thenReturn(1); | ||
ShadowRule result = mock(ShadowRule.class); | ||
when(result.getAttributes()).thenReturn(new RuleAttributes(dataSourceMapperRuleAttribute)); | ||
return result; | ||
} | ||
|
||
@Test | ||
void assertGetRuleClass() { | ||
assertThat(builder.getRuleClass(), is(ShadowRule.class)); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...ache/shardingsphere/sharding/distsql/handler/query/ShardingCountResultRowBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.sharding.distsql.handler.query; | ||
|
||
import org.apache.shardingsphere.distsql.handler.executor.rql.rule.CountResultRowBuilder; | ||
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; | ||
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; | ||
import org.apache.shardingsphere.sharding.rule.ShardingRule; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class ShardingCountResultRowBuilderTest { | ||
|
||
@SuppressWarnings("unchecked") | ||
private final CountResultRowBuilder<ShardingRule> builder = TypedSPILoader.getService(CountResultRowBuilder.class, "SHARDING"); | ||
|
||
@Test | ||
void assertGenerateRows() { | ||
List<LocalDataQueryResultRow> actual = new ArrayList<>(builder.generateRows(mockRule(), "foo_db")); | ||
assertThat(actual.size(), is(2)); | ||
assertThat(actual.get(0).getCell(1), is("sharding_table")); | ||
assertThat(actual.get(0).getCell(2), is("foo_db")); | ||
assertThat(actual.get(0).getCell(3), is("1")); | ||
assertThat(actual.get(1).getCell(1), is("sharding_table_reference")); | ||
assertThat(actual.get(1).getCell(2), is("foo_db")); | ||
assertThat(actual.get(1).getCell(3), is("1")); | ||
} | ||
|
||
private ShardingRule mockRule() { | ||
ShardingRule result = mock(ShardingRule.class, RETURNS_DEEP_STUBS); | ||
when(result.getShardingTables().size()).thenReturn(1); | ||
when(result.getConfiguration().getBindingTableGroups().size()).thenReturn(1); | ||
return result; | ||
} | ||
|
||
@Test | ||
void assertGetRuleClass() { | ||
assertThat(builder.getRuleClass(), is(ShardingRule.class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.