You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2022/10/25 01:51:36 UTC
[shardingsphere] branch master updated: Adding test to ConnectionSavepointManager (#21367)
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 5c1c7c39524 Adding test to ConnectionSavepointManager (#21367)
5c1c7c39524 is described below
commit 5c1c7c39524e725f78c50334e203a3466060b13f
Author: Gabriel Cunha <cu...@gmail.com>
AuthorDate: Mon Oct 24 22:51:26 2022 -0300
Adding test to ConnectionSavepointManager (#21367)
* Adding test to ConnectionSavepointManager
* Code review
* removing blank lines
* Adding more tests
* Replacing initMocks
---
.../ConnectionSavepointManagerTest.java | 73 ++++++++++++++++++++++
1 file changed, 73 insertions(+)
diff --git a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/ConnectionSavepointManagerTest.java b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/ConnectionSavepointManagerTest.java
new file mode 100644
index 00000000000..325836534cf
--- /dev/null
+++ b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/ConnectionSavepointManagerTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.transaction;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Savepoint;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class ConnectionSavepointManagerTest {
+
+ private static final String SAVE_POINT = "SavePoint";
+
+ @Mock
+ private Connection connection;
+
+ @Mock
+ private Savepoint savepoint;
+
+ @InjectMocks
+ private ConnectionSavepointManager connectionSavepointManager;
+
+ @Before
+ public void setup() throws SQLException {
+ when(connection.setSavepoint(SAVE_POINT)).thenReturn(savepoint);
+ }
+
+ @Test
+ public void testSetSavepoint() throws SQLException {
+ connectionSavepointManager.setSavepoint(connection, SAVE_POINT);
+ verify(connection, times(1)).setSavepoint(SAVE_POINT);
+ }
+
+ @Test
+ public void testRollbackToSavepoint() throws SQLException {
+ connectionSavepointManager.setSavepoint(connection, SAVE_POINT);
+ connectionSavepointManager.rollbackToSavepoint(connection, SAVE_POINT);
+ verify(connection, times(1)).rollback(savepoint);
+ }
+
+ @Test
+ public void testSaveReleaseSavingPoint() throws SQLException {
+ connectionSavepointManager.setSavepoint(connection, SAVE_POINT);
+ connectionSavepointManager.releaseSavepoint(connection, SAVE_POINT);
+ verify(connection, times(1)).releaseSavepoint(savepoint);
+ }
+}