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/06/26 13:07:01 UTC

[GitHub] [shardingsphere] TaoZhiMLND opened a new pull request #6189: add unit test for sharding-transaction-xa-narayana-manager module.

TaoZhiMLND opened a new pull request #6189:
URL: https://github.com/apache/shardingsphere/pull/6189


   For #5302.
   


----------------------------------------------------------------
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



[GitHub] [shardingsphere] cherrylzhao commented on pull request #6189: add unit test for sharding-transaction-xa-narayana-manager module.

Posted by GitBox <gi...@apache.org>.
cherrylzhao commented on pull request #6189:
URL: https://github.com/apache/shardingsphere/pull/6189#issuecomment-663862012


   I'll merge this PR, then fix the checkstyle later.


----------------------------------------------------------------
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



[GitHub] [shardingsphere] cherrylzhao commented on a change in pull request #6189: add unit test for sharding-transaction-xa-narayana-manager module.

Posted by GitBox <gi...@apache.org>.
cherrylzhao commented on a change in pull request #6189:
URL: https://github.com/apache/shardingsphere/pull/6189#discussion_r446589194



##########
File path: shardingsphere-transaction/shardingsphere-transaction-2pc/shardingsphere-transaction-xa/shardingsphere-transaction-xa-narayana/src/test/java/org/apache/shardingsphere/transaction/xa/narayana/manager/DataSourceXAResourceRecoveryHelperTest.java
##########
@@ -0,0 +1,164 @@
+/*
+ * 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.xa.narayana.manager;
+
+import javax.sql.XAConnection;
+import javax.sql.XADataSource;
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.transaction.xa.narayana.manager.fixture.ReflectiveUtil;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DataSourceXAResourceRecoveryHelperTest {
+    
+    @Mock
+    private XADataSource xaDataSource;
+    
+    @Mock
+    private XAResource xaResource;
+    
+    @Mock
+    private XAConnection xaConnection;
+    
+    private DataSourceXAResourceRecoveryHelper recoveryHelper;
+    
+    @SneakyThrows
+    @Before
+    public void setUp() {
+        when(xaConnection.getXAResource()).thenReturn(xaResource);
+        when(xaDataSource.getXAConnection()).thenReturn(xaConnection);
+        recoveryHelper = new DataSourceXAResourceRecoveryHelper(xaDataSource);
+    }
+    
+    @SneakyThrows
+    @Test
+    public void assertGetXAResourcesCreatingConnecting() {
+        recoveryHelper.getXAResources();
+        XAResource[] xaResources = recoveryHelper.getXAResources();
+        assertEquals(1, xaResources.length);
+        Assert.assertThat(xaResources[0], sameInstance(recoveryHelper));

Review comment:
       for check style: we can import static import Assert.assert here
   `Assert.assertThat()` => `assertThat()`

##########
File path: shardingsphere-transaction/shardingsphere-transaction-2pc/shardingsphere-transaction-xa/shardingsphere-transaction-xa-narayana/src/main/java/org/apache/shardingsphere/transaction/xa/narayana/manager/DataSourceXAResourceRecoveryHelper.java
##########
@@ -124,51 +124,51 @@ private void disconnect() {
     
     @Override
     public void start(final Xid xid, final int flags) throws XAException {
-        getDelegate(true).start(xid, flags);
+        getDelegate().start(xid, flags);
     }
     
     @Override
     public void end(final Xid xid, final int flags) throws XAException {
-        getDelegate(true).end(xid, flags);
+        getDelegate().end(xid, flags);
     }
     
     @Override
     public int prepare(final Xid xid) throws XAException {
-        return getDelegate(true).prepare(xid);
+        return getDelegate().prepare(xid);
     }
     
     @Override
     public void commit(final Xid xid, final boolean onePhase) throws XAException {
-        getDelegate(true).commit(xid, onePhase);
+        getDelegate().commit(xid, onePhase);
     }
     
     @Override
     public void rollback(final Xid xid) throws XAException {
-        getDelegate(true).rollback(xid);
+        getDelegate().rollback(xid);
     }
     
     @Override
     public boolean isSameRM(final XAResource xaResource) throws XAException {
-        return getDelegate(true).isSameRM(xaResource);
+        return getDelegate().isSameRM(xaResource);
     }
     
     @Override
     public void forget(final Xid xid) throws XAException {
-        getDelegate(true).forget(xid);
+        getDelegate().forget(xid);
     }
     
     @Override
     public int getTransactionTimeout() throws XAException {
-        return getDelegate(true).getTransactionTimeout();
+        return getDelegate().getTransactionTimeout();
     }
     
     @Override
     public boolean setTransactionTimeout(final int seconds) throws XAException {
-        return getDelegate(true).setTransactionTimeout(seconds);
+        return getDelegate().setTransactionTimeout(seconds);
     }
     
-    private XAResource getDelegate(final boolean required) {
-        if (this.delegate == null && required) {
+    private XAResource getDelegate() {
+        if (this.delegate == null) {

Review comment:
       for checkstyle: `this.delegate == null` => `null == this.delegate`




----------------------------------------------------------------
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



[GitHub] [shardingsphere] cherrylzhao merged pull request #6189: add unit test for sharding-transaction-xa-narayana-manager module.

Posted by GitBox <gi...@apache.org>.
cherrylzhao merged pull request #6189:
URL: https://github.com/apache/shardingsphere/pull/6189


   


----------------------------------------------------------------
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