You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/08/30 15:25:18 UTC

[GitHub] [shardingsphere] terrymanu commented on a change in pull request #7154: Add test case of StandardTransactionContexts

terrymanu commented on a change in pull request #7154:
URL: https://github.com/apache/shardingsphere/pull/7154#discussion_r479782404



##########
File path: shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/context/impl/StandardTransactionContextsTest.java
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.context.impl;
+
+import org.apache.shardingsphere.infra.database.DefaultSchema;
+import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+
+public class StandardTransactionContextsTest {

Review comment:
       Please add final if the class is not design for extension

##########
File path: shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/context/impl/StandardTransactionContextsTest.java
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.context.impl;
+
+import org.apache.shardingsphere.infra.database.DefaultSchema;
+import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+
+public class StandardTransactionContextsTest {
+    
+    @Test
+    public void assertGetEnginesNull() {
+        StandardTransactionContexts standardTransactionContexts = new StandardTransactionContexts();
+        Map<String, ShardingTransactionManagerEngine> engines = standardTransactionContexts.getEngines();
+        Assert.assertTrue(engines.isEmpty());
+    }
+    
+    @Test
+    public void assertGetEngines() {
+        Map<String, ShardingTransactionManagerEngine> actualEngine = new HashMap<>();
+        actualEngine.put(DefaultSchema.LOGIC_NAME, new ShardingTransactionManagerEngine());
+        StandardTransactionContexts standardTransactionContexts = new StandardTransactionContexts(actualEngine);
+        
+        Map<String, ShardingTransactionManagerEngine> engines = standardTransactionContexts.getEngines();
+        Assert.assertThat(engines.size(), is(1));
+        Assert.assertThat(engines, is(actualEngine));
+        ShardingTransactionManagerEngine defaultEngine = standardTransactionContexts.getDefaultTransactionManagerEngine();
+        Assert.assertNotNull(defaultEngine);

Review comment:
       Please use static import with `Assert. assertNotNull`

##########
File path: shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/context/impl/StandardTransactionContextsTest.java
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.context.impl;
+
+import org.apache.shardingsphere.infra.database.DefaultSchema;
+import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+
+public class StandardTransactionContextsTest {
+    
+    @Test
+    public void assertGetEnginesNull() {
+        StandardTransactionContexts standardTransactionContexts = new StandardTransactionContexts();
+        Map<String, ShardingTransactionManagerEngine> engines = standardTransactionContexts.getEngines();
+        Assert.assertTrue(engines.isEmpty());
+    }
+    
+    @Test
+    public void assertGetEngines() {
+        Map<String, ShardingTransactionManagerEngine> actualEngine = new HashMap<>();
+        actualEngine.put(DefaultSchema.LOGIC_NAME, new ShardingTransactionManagerEngine());
+        StandardTransactionContexts standardTransactionContexts = new StandardTransactionContexts(actualEngine);
+        
+        Map<String, ShardingTransactionManagerEngine> engines = standardTransactionContexts.getEngines();
+        Assert.assertThat(engines.size(), is(1));
+        Assert.assertThat(engines, is(actualEngine));

Review comment:
       Please use static import with `Assert. assertThat`

##########
File path: shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/context/impl/StandardTransactionContextsTest.java
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.context.impl;
+
+import org.apache.shardingsphere.infra.database.DefaultSchema;
+import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+
+public class StandardTransactionContextsTest {
+    
+    @Test
+    public void assertGetEnginesNull() {
+        StandardTransactionContexts standardTransactionContexts = new StandardTransactionContexts();
+        Map<String, ShardingTransactionManagerEngine> engines = standardTransactionContexts.getEngines();
+        Assert.assertTrue(engines.isEmpty());

Review comment:
       Please use static import with `Assert.assertTrue`

##########
File path: shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/context/impl/StandardTransactionContextsTest.java
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.context.impl;
+
+import org.apache.shardingsphere.infra.database.DefaultSchema;
+import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+
+public class StandardTransactionContextsTest {
+    
+    @Test
+    public void assertGetEnginesNull() {

Review comment:
       What's mean of`assertGetEnginesNull`? Do you mean `assertNewInstanceWithEmptyEngines`?

##########
File path: shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/context/impl/StandardTransactionContextsTest.java
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.context.impl;
+
+import org.apache.shardingsphere.infra.database.DefaultSchema;
+import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+
+public class StandardTransactionContextsTest {
+    
+    @Test
+    public void assertGetEnginesNull() {
+        StandardTransactionContexts standardTransactionContexts = new StandardTransactionContexts();
+        Map<String, ShardingTransactionManagerEngine> engines = standardTransactionContexts.getEngines();
+        Assert.assertTrue(engines.isEmpty());
+    }
+    
+    @Test
+    public void assertGetEngines() {
+        Map<String, ShardingTransactionManagerEngine> actualEngine = new HashMap<>();
+        actualEngine.put(DefaultSchema.LOGIC_NAME, new ShardingTransactionManagerEngine());
+        StandardTransactionContexts standardTransactionContexts = new StandardTransactionContexts(actualEngine);
+        

Review comment:
       Please remove useless empty line

##########
File path: shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/context/impl/StandardTransactionContextsTest.java
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.context.impl;
+
+import org.apache.shardingsphere.infra.database.DefaultSchema;
+import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+
+public class StandardTransactionContextsTest {
+    
+    @Test
+    public void assertGetEnginesNull() {
+        StandardTransactionContexts standardTransactionContexts = new StandardTransactionContexts();
+        Map<String, ShardingTransactionManagerEngine> engines = standardTransactionContexts.getEngines();
+        Assert.assertTrue(engines.isEmpty());
+    }
+    
+    @Test
+    public void assertGetEngines() {

Review comment:
       It seems we do not need to assert method `getEngines` which is for simple getter only.
   It is necessary to assert method `getDefaultTransactionManagerEngine`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org