This is an automated email from the ASF dual-hosted git repository.
wuweijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new ee2e6b89ac5 Support return mysql auto increment generated id when use
Proxy (#23612)
ee2e6b89ac5 is described below
commit ee2e6b89ac53c469ccb3d99e7c8835a661d349e8
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Tue Jan 17 18:47:33 2023 +0800
Support return mysql auto increment generated id when use Proxy (#23612)
* Support return mysql auto increment generated id when use Proxy
* modify code style
* update unit test
* Use ArrayList for better performance
---
.../sharding/spi/KeyGenerateAlgorithm.java | 9 ++++
.../impl/InsertClauseShardingConditionEngine.java | 1 +
.../shardingsphere/sharding/rule/ShardingRule.java | 17 +++++++-
.../AutoIncrementKeyGenerateAlgorithmFixture.java | 11 +++--
.../sharding/rule/ShardingRuleTest.java | 8 ++++
...hardingsphere.sharding.spi.KeyGenerateAlgorithm | 18 ++++++++
.../segment/insert/keygen/GeneratedKeyContext.java | 4 ++
.../IncrementKeyGenerateAlgorithmFixture.java | 5 +++
.../ResetIncrementKeyGenerateAlgorithmFixture.java | 5 +++
.../communication/DatabaseCommunicationEngine.java | 9 +++-
.../header/update/UpdateResponseHeader.java | 30 ++++++++++---
.../header/update/UpdateResponseHeaderTest.java | 49 +++++++++++++++-------
.../util/AutoIncrementKeyGenerateAlgorithm.java | 5 +++
13 files changed, 143 insertions(+), 28 deletions(-)
diff --git
a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/spi/KeyGenerateAlgorithm.java
b/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/spi/KeyGenerateAlgorithm.java
index 1c6e12791ef..91bab11c48c 100644
---
a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/spi/KeyGenerateAlgorithm.java
+++
b/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/spi/KeyGenerateAlgorithm.java
@@ -31,4 +31,13 @@ public interface KeyGenerateAlgorithm extends
ShardingSphereAlgorithm, RequiredS
* @return generated key
*/
Comparable<?> generateKey();
+
+ /**
+ * Judge whether support auto increment or not.
+ *
+ * @return whether support auto increment or not
+ */
+ default boolean isSupportAutoIncrement() {
+ return false;
+ }
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java
index 787536cec11..6b0731edb0a 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java
@@ -156,6 +156,7 @@ public final class InsertClauseShardingConditionEngine {
String tableName =
sqlStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue();
if (generatedKey.isPresent() && generatedKey.get().isGenerated() &&
shardingRule.findTableRule(tableName).isPresent()) {
generatedKey.get().getGeneratedValues().addAll(generateKeys(tableName,
sqlStatementContext.getValueListCount()));
+
generatedKey.get().setSupportAutoIncrement(shardingRule.isSupportAutoIncrement(tableName));
if
(shardingRule.findShardingColumn(generatedKey.get().getColumnName(),
tableName).isPresent()) {
appendGeneratedKeyCondition(generatedKey.get(), tableName,
shardingConditions);
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index 15befb15540..d24b252dd0e 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -588,10 +588,23 @@ public final class ShardingRule implements DatabaseRule,
DataNodeContainedRule,
* @return generated key
*/
public Comparable<?> generateKey(final String logicTableName) {
+ return getKeyGenerateAlgorithm(logicTableName).generateKey();
+ }
+
+ private KeyGenerateAlgorithm getKeyGenerateAlgorithm(final String
logicTableName) {
Optional<TableRule> tableRule = findTableRule(logicTableName);
ShardingSpherePreconditions.checkState(tableRule.isPresent(), () ->
new GenerateKeyStrategyNotFoundException(logicTableName));
- KeyGenerateAlgorithm keyGenerator = null !=
tableRule.get().getKeyGeneratorName() ?
keyGenerators.get(tableRule.get().getKeyGeneratorName()) :
defaultKeyGenerateAlgorithm;
- return keyGenerator.generateKey();
+ return null != tableRule.get().getKeyGeneratorName() ?
keyGenerators.get(tableRule.get().getKeyGeneratorName()) :
defaultKeyGenerateAlgorithm;
+ }
+
+ /**
+ * Judge whether support auto increment or not.
+ *
+ * @param logicTableName logic table name
+ * @return whether support auto increment or not
+ */
+ public boolean isSupportAutoIncrement(final String logicTableName) {
+ return
getKeyGenerateAlgorithm(logicTableName).isSupportAutoIncrement();
}
/**
diff --git
a/jdbc/core/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/keygen/IncrementKeyGenerateAlgorithmFixture.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/fixture/AutoIncrementKeyGenerateAlgorithmFixture.java
similarity index 81%
copy from
jdbc/core/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/keygen/IncrementKeyGenerateAlgorithmFixture.java
copy to
features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/fixture/AutoIncrementKeyGenerateAlgorithmFixture.java
index a71dc35e7e6..db7aa968cff 100644
---
a/jdbc/core/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/keygen/IncrementKeyGenerateAlgorithmFixture.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/fixture/AutoIncrementKeyGenerateAlgorithmFixture.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.e2e.driver.fixture.keygen;
+package org.apache.shardingsphere.sharding.algorithm.keygen.fixture;
import lombok.Getter;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
@@ -24,7 +24,7 @@ import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
@Getter
-public final class IncrementKeyGenerateAlgorithmFixture implements
KeyGenerateAlgorithm {
+public final class AutoIncrementKeyGenerateAlgorithmFixture implements
KeyGenerateAlgorithm {
private final AtomicInteger count = new AtomicInteger();
@@ -42,6 +42,11 @@ public final class IncrementKeyGenerateAlgorithmFixture
implements KeyGenerateAl
@Override
public String getType() {
- return "JDBC.INCREMENT.FIXTURE";
+ return "AUTO_INCREMENT.FIXTURE";
+ }
+
+ @Override
+ public boolean isSupportAutoIncrement() {
+ return true;
}
}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
index 4da3e9e0ae5..79fcfb4f9bc 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
@@ -461,6 +461,7 @@ public final class ShardingRuleTest {
ShardingTableRuleConfiguration shardingTableRuleConfig =
createTableRuleConfiguration("LOGIC_TABLE", "ds_${0..1}.table_${0..2}");
shardingTableRuleConfig.setKeyGenerateStrategy(new
KeyGenerateStrategyConfiguration("id", "uuid"));
ShardingTableRuleConfiguration subTableRuleConfig =
createTableRuleConfiguration("SUB_LOGIC_TABLE", "ds_${0..1}.sub_table_${0..2}");
+ subTableRuleConfig.setKeyGenerateStrategy(new
KeyGenerateStrategyConfiguration("id", "auto_increment"));
shardingRuleConfig.getTables().add(shardingTableRuleConfig);
shardingRuleConfig.getTables().add(subTableRuleConfig);
shardingRuleConfig.getBindingTableGroups().add(new
ShardingTableReferenceRuleConfiguration("foo",
shardingTableRuleConfig.getLogicTable() + "," +
subTableRuleConfig.getLogicTable()));
@@ -473,6 +474,7 @@ public final class ShardingRuleTest {
shardingRuleConfig.getShardingAlgorithms().put("core_standard_fixture", new
AlgorithmConfiguration("CORE.STANDARD.FIXTURE", new Properties()));
shardingRuleConfig.getKeyGenerators().put("uuid", new
AlgorithmConfiguration("UUID", new Properties()));
shardingRuleConfig.getKeyGenerators().put("default", new
AlgorithmConfiguration("UUID", new Properties()));
+ shardingRuleConfig.getKeyGenerators().put("auto_increment", new
AlgorithmConfiguration("AUTO_INCREMENT.FIXTURE", new Properties()));
shardingRuleConfig.getAuditors().put("audit_algorithm", new
AlgorithmConfiguration("DML_SHARDING_CONDITIONS", new Properties()));
return new ShardingRule(shardingRuleConfig, createDataSourceNames(),
mock(InstanceContext.class));
}
@@ -785,4 +787,10 @@ public final class ShardingRuleTest {
Optional<String> actualTableByCatalog =
actual.findActualTableByCatalog("ds_0", "logic_table");
assertThat(actualTableByCatalog.orElse(""), is("table_0"));
}
+
+ @Test
+ public void assertIsSupportAutoIncrement() {
+
assertFalse(createMaximumShardingRule().isSupportAutoIncrement("logic_table"));
+
assertTrue(createMaximumShardingRule().isSupportAutoIncrement("sub_logic_table"));
+ }
}
diff --git
a/features/sharding/core/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm
b/features/sharding/core/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm
new file mode 100644
index 00000000000..f1b7b845bb2
--- /dev/null
+++
b/features/sharding/core/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.sharding.algorithm.keygen.fixture.AutoIncrementKeyGenerateAlgorithmFixture
diff --git
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/insert/keygen/GeneratedKeyContext.java
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/insert/keygen/GeneratedKeyContext.java
index 60be6cd981e..70f5e7413ca 100644
---
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/insert/keygen/GeneratedKeyContext.java
+++
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/insert/keygen/GeneratedKeyContext.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.infra.binder.segment.insert.keygen;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import lombok.Setter;
import lombok.ToString;
import java.util.Collection;
@@ -36,5 +37,8 @@ public final class GeneratedKeyContext {
private final boolean generated;
+ @Setter
+ private boolean supportAutoIncrement;
+
private final Collection<Comparable<?>> generatedValues = new
LinkedList<>();
}
diff --git
a/jdbc/core/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/keygen/IncrementKeyGenerateAlgorithmFixture.java
b/jdbc/core/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/keygen/IncrementKeyGenerateAlgorithmFixture.java
index a71dc35e7e6..6ddd61dd7ba 100644
---
a/jdbc/core/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/keygen/IncrementKeyGenerateAlgorithmFixture.java
+++
b/jdbc/core/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/keygen/IncrementKeyGenerateAlgorithmFixture.java
@@ -44,4 +44,9 @@ public final class IncrementKeyGenerateAlgorithmFixture
implements KeyGenerateAl
public String getType() {
return "JDBC.INCREMENT.FIXTURE";
}
+
+ @Override
+ public boolean isSupportAutoIncrement() {
+ return true;
+ }
}
diff --git
a/jdbc/core/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/keygen/ResetIncrementKeyGenerateAlgorithmFixture.java
b/jdbc/core/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/keygen/ResetIncrementKeyGenerateAlgorithmFixture.java
index 046b5050d44..c0fcd38a3ce 100644
---
a/jdbc/core/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/keygen/ResetIncrementKeyGenerateAlgorithmFixture.java
+++
b/jdbc/core/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/keygen/ResetIncrementKeyGenerateAlgorithmFixture.java
@@ -45,4 +45,9 @@ public final class ResetIncrementKeyGenerateAlgorithmFixture
implements KeyGener
public String getType() {
return "JDBC.RESET_INCREMENT.FIXTURE";
}
+
+ @Override
+ public boolean isSupportAutoIncrement() {
+ return true;
+ }
}
diff --git
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
index 45ee24ec90f..e1f35952564 100644
---
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
+++
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
@@ -22,9 +22,11 @@ import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.infra.binder.aware.CursorDefinitionAware;
import
org.apache.shardingsphere.infra.binder.decider.context.SQLFederationDeciderContext;
import
org.apache.shardingsphere.infra.binder.decider.engine.SQLFederationDeciderEngine;
+import
org.apache.shardingsphere.infra.binder.segment.insert.keygen.GeneratedKeyContext;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.ddl.CloseStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.ddl.CursorStatementContext;
+import
org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.type.CursorAvailable;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
@@ -299,7 +301,12 @@ public final class DatabaseCommunicationEngine implements
DatabaseBackendHandler
}
private UpdateResponseHeader processExecuteUpdate(final ExecutionContext
executionContext, final Collection<UpdateResult> updateResults) {
- UpdateResponseHeader result = new
UpdateResponseHeader(executionContext.getSqlStatementContext().getSqlStatement(),
updateResults);
+ Optional<GeneratedKeyContext> generatedKeyContext =
executionContext.getSqlStatementContext() instanceof InsertStatementContext
+ ? ((InsertStatementContext)
executionContext.getSqlStatementContext()).getGeneratedKeyContext()
+ : Optional.empty();
+ Collection<Comparable<?>> autoIncrementGeneratedValues =
+
generatedKeyContext.filter(GeneratedKeyContext::isSupportAutoIncrement).map(GeneratedKeyContext::getGeneratedValues).orElseGet(Collections::emptyList);
+ UpdateResponseHeader result = new
UpdateResponseHeader(executionContext.getSqlStatementContext().getSqlStatement(),
updateResults, autoIncrementGeneratedValues);
mergeUpdateCount(executionContext.getSqlStatementContext(), result);
return result;
}
diff --git
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/update/UpdateResponseHeader.java
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/update/UpdateResponseHeader.java
index cc7584b2d51..52c7d2d22b2 100644
---
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/update/UpdateResponseHeader.java
+++
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/update/UpdateResponseHeader.java
@@ -23,9 +23,11 @@ import
org.apache.shardingsphere.infra.executor.sql.execute.result.update.Update
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
+import java.util.List;
/**
* Update response header.
@@ -43,24 +45,40 @@ public final class UpdateResponseHeader implements
ResponseHeader {
private long updateCount;
public UpdateResponseHeader(final SQLStatement sqlStatement) {
- this(sqlStatement, Collections.emptyList());
+ this(sqlStatement, Collections.emptyList(), Collections.emptyList());
}
public UpdateResponseHeader(final SQLStatement sqlStatement, final
Collection<UpdateResult> updateResults) {
+ this(sqlStatement, updateResults, Collections.emptyList());
+ }
+
+ public UpdateResponseHeader(final SQLStatement sqlStatement, final
Collection<UpdateResult> updateResults, final Collection<Comparable<?>>
autoIncrementGeneratedValues) {
this.sqlStatement = sqlStatement;
- lastInsertId = getLastInsertId(updateResults);
+ lastInsertId = getLastInsertId(updateResults,
autoIncrementGeneratedValues);
updateCount = updateResults.iterator().hasNext() ?
updateResults.iterator().next().getUpdateCount() : 0;
for (UpdateResult each : updateResults) {
updateCounts.add(each.getUpdateCount());
}
}
- private long getLastInsertId(final Collection<UpdateResult> updateResults)
{
- long result = 0;
+ private long getLastInsertId(final Collection<UpdateResult> updateResults,
final Collection<Comparable<?>> autoIncrementGeneratedValues) {
+ List<Long> lastInsertIds = new ArrayList<>(updateResults.size() +
autoIncrementGeneratedValues.size());
for (UpdateResult each : updateResults) {
- result = Math.max(result, each.getLastInsertId());
+ if (each.getLastInsertId() > 0) {
+ lastInsertIds.add(each.getLastInsertId());
+ }
+ }
+ for (Comparable<?> each : autoIncrementGeneratedValues) {
+ if (each instanceof Number) {
+ lastInsertIds.add(((Number) each).longValue());
+ }
}
- return result;
+ return lastInsertIds.isEmpty() ? 0 : getMinLastInsertId(lastInsertIds);
+ }
+
+ private static long getMinLastInsertId(final List<Long> lastInsertIds) {
+ Collections.sort(lastInsertIds);
+ return lastInsertIds.iterator().next();
}
/**
diff --git
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/response/header/update/UpdateResponseHeaderTest.java
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/response/header/update/UpdateResponseHeaderTest.java
index 9f85fa58634..31c0e21c961 100644
---
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/response/header/update/UpdateResponseHeaderTest.java
+++
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/response/header/update/UpdateResponseHeaderTest.java
@@ -23,6 +23,7 @@ import org.junit.Test;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -31,26 +32,42 @@ import static org.mockito.Mockito.mock;
public final class UpdateResponseHeaderTest {
@Test
- public void assertPropertiesWhenExecuteResultOfEmptyList() {
- UpdateResponseHeader updateResponseHeader = new
UpdateResponseHeader(mock(SQLStatement.class));
- assertThat(updateResponseHeader.getLastInsertId(), is(0L));
- assertThat(updateResponseHeader.getUpdateCount(), is(0L));
- updateResponseHeader.mergeUpdateCount();
- assertThat(updateResponseHeader.getUpdateCount(), is(0L));
+ public void assertGetLastInsertIdWhenExecuteResultIsEmpty() {
+ UpdateResponseHeader actual = new
UpdateResponseHeader(mock(SQLStatement.class));
+ assertThat(actual.getLastInsertId(), is(0L));
}
@Test
- public void assertPropertiesWhenExecuteResultOfNotEmptyList() {
- UpdateResponseHeader updateResponseHeader = new
UpdateResponseHeader(mock(SQLStatement.class), getExecuteUpdateResults());
- assertThat(updateResponseHeader.getLastInsertId(), is(4L));
- assertThat(updateResponseHeader.getUpdateCount(), is(1L));
- updateResponseHeader.mergeUpdateCount();
- assertThat(updateResponseHeader.getUpdateCount(), is(4L));
+ public void assertGetLastInsertIdWhenExecuteResultIsNotEmpty() {
+ UpdateResponseHeader actual = new
UpdateResponseHeader(mock(SQLStatement.class), createExecuteUpdateResults());
+ assertThat(actual.getLastInsertId(), is(2L));
}
- private Collection<UpdateResult> getExecuteUpdateResults() {
- UpdateResult updateResult1 = new UpdateResult(1, 2L);
- UpdateResult updateResult2 = new UpdateResult(3, 4L);
- return Arrays.asList(updateResult1, updateResult2);
+ private Collection<UpdateResult> createExecuteUpdateResults() {
+ return Arrays.asList(new UpdateResult(0, 0L), new UpdateResult(1, 2L),
new UpdateResult(3, 4L));
+ }
+
+ @Test
+ public void assertGetLastInsertIdWhenAutoGeneratedIdIsNotEmpty() {
+ UpdateResponseHeader actual = new
UpdateResponseHeader(mock(SQLStatement.class), Collections.emptyList(),
createAutoIncrementGeneratedValues());
+ assertThat(actual.getLastInsertId(), is(1L));
+ }
+
+ private Collection<Comparable<?>> createAutoIncrementGeneratedValues() {
+ return Arrays.asList(1, 2, 3, 4);
+ }
+
+ @Test
+ public void assertGetUpdateCountWhenExecuteResultIsEmpty() {
+ UpdateResponseHeader actual = new
UpdateResponseHeader(mock(SQLStatement.class));
+ assertThat(actual.getUpdateCount(), is(0L));
+ }
+
+ @Test
+ public void assertGetUpdateCountWhenExecuteResultIsNotEmpty() {
+ UpdateResponseHeader actual = new
UpdateResponseHeader(mock(SQLStatement.class), createExecuteUpdateResults());
+ assertThat(actual.getUpdateCount(), is(0L));
+ actual.mergeUpdateCount();
+ assertThat(actual.getUpdateCount(), is(4L));
}
}
diff --git
a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/util/AutoIncrementKeyGenerateAlgorithm.java
b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/util/AutoIncrementKeyGenerateAlgorithm.java
index 69f884bb7a1..b61dca3d3b2 100644
---
a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/util/AutoIncrementKeyGenerateAlgorithm.java
+++
b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/util/AutoIncrementKeyGenerateAlgorithm.java
@@ -39,4 +39,9 @@ public final class AutoIncrementKeyGenerateAlgorithm
implements KeyGenerateAlgor
@Override
public void init(final Properties props) {
}
+
+ @Override
+ public boolean isSupportAutoIncrement() {
+ return true;
+ }
}