You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by es...@apache.org on 2018/01/11 18:36:37 UTC

[geode] branch feature/GEODE-4204-4207-pre updated: GEODE-4204: GEODE-4207: pass in cache instead of using singleton

This is an automated email from the ASF dual-hosted git repository.

eshu11 pushed a commit to branch feature/GEODE-4204-4207-pre
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-4204-4207-pre by this push:
     new cecc9f7  GEODE-4204: GEODE-4207: pass in cache instead of using singleton
cecc9f7 is described below

commit cecc9f7cfe28defceda9db549a3c39ac6a84d9e1
Author: eshu <es...@pivotal.io>
AuthorDate: Thu Jan 11 10:36:09 2018 -0800

    GEODE-4204: GEODE-4207: pass in cache instead of using singleton
---
 .../cache/DistTXStateProxyImplOnCoordinator.java   |  3 +-
 .../internal/cache/TXRegionLockRequestImpl.java    | 33 +++++----
 .../apache/geode/internal/cache/TXRegionState.java |  4 +-
 .../geode/internal/cache/TXStateProxyImpl.java     |  3 +-
 .../geode/internal/cache/tx/ClientTXStateStub.java | 61 +++++++++-------
 .../internal/cache/tx/DistClientTXStateStub.java   | 16 ++---
 .../cache/TXRegionLockRequestImplTest.java         | 55 +++++++++++++++
 .../internal/cache/TXReservationMgrJUnitTest.java  |  2 +-
 .../internal/cache/tx/ClientTXStateStubTest.java   | 82 ++++++++++++++++++++++
 9 files changed, 201 insertions(+), 58 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/DistTXStateProxyImplOnCoordinator.java b/geode-core/src/main/java/org/apache/geode/internal/cache/DistTXStateProxyImplOnCoordinator.java
index a477d6c..0b0e260 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/DistTXStateProxyImplOnCoordinator.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/DistTXStateProxyImplOnCoordinator.java
@@ -331,7 +331,8 @@ public class DistTXStateProxyImplOnCoordinator extends DistTXStateProxyImpl {
         // Code to keep going forward
         if (r.hasServerProxy()) {
           // TODO [DISTTX] See what we need for client?
-          this.realDeal = new DistClientTXStateStub(this, target, r);
+          this.realDeal =
+              new DistClientTXStateStub(r.getCache(), r.getDistributionManager(), this, target, r);
           if (r.scope.isDistributed()) {
             if (txDistributedClientWarningIssued.compareAndSet(false, true)) {
               logger.warn(LocalizedMessage.create(
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/TXRegionLockRequestImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/TXRegionLockRequestImpl.java
index 1e586aa..e0e058c 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/TXRegionLockRequestImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/TXRegionLockRequestImpl.java
@@ -23,6 +23,7 @@ import java.util.Set;
 import org.apache.logging.log4j.Logger;
 
 import org.apache.geode.DataSerializer;
+import org.apache.geode.annotations.TestingOnly;
 import org.apache.geode.cache.CacheClosedException;
 import org.apache.geode.internal.InternalDataSerializer;
 import org.apache.geode.internal.cache.locks.TXRegionLockRequest;
@@ -38,6 +39,8 @@ public class TXRegionLockRequestImpl implements TXRegionLockRequest {
   private static final long serialVersionUID = 5840033961584078082L;
   private static final Logger logger = LogService.getLogger();
 
+  private InternalCache cache;
+
   private transient LocalRegion r;
 
   private String regionPath;
@@ -46,9 +49,11 @@ public class TXRegionLockRequestImpl implements TXRegionLockRequest {
 
   public TXRegionLockRequestImpl() {
     // for DataSerializer
+    this.cache = null;
   }
 
-  public TXRegionLockRequestImpl(LocalRegion r) {
+  public TXRegionLockRequestImpl(InternalCache cache, LocalRegion r) {
+    this.cache = cache;
     this.r = r;
     this.regionPath = null;
     this.entryKeys = null;
@@ -57,7 +62,9 @@ public class TXRegionLockRequestImpl implements TXRegionLockRequest {
   /**
    * Used by unit tests
    */
+  @TestingOnly
   public TXRegionLockRequestImpl(String regionPath, Set<Object> entryKeys) {
+    this.cache = null;
     this.regionPath = regionPath;
     this.entryKeys = entryKeys;
   }
@@ -66,6 +73,7 @@ public class TXRegionLockRequestImpl implements TXRegionLockRequest {
     return this.entryKeys == null || this.entryKeys.isEmpty();
   }
 
+  @Override
   public void addEntryKeys(Set<Object> s) {
     if (s == null || s.isEmpty()) {
       return;
@@ -85,6 +93,7 @@ public class TXRegionLockRequestImpl implements TXRegionLockRequest {
     }
   }
 
+  @Override
   public void addEntryKey(Object key) {
     if (this.entryKeys == null) {
       this.entryKeys = new HashSet<Object>();
@@ -92,10 +101,11 @@ public class TXRegionLockRequestImpl implements TXRegionLockRequest {
     this.entryKeys.add(key);
   }
 
+  @Override
   public void fromData(DataInput in) throws IOException, ClassNotFoundException {
     this.regionPath = DataSerializer.readString(in);
 
-    final InternalCache cache = getCache(false);
+    cache = GemFireCacheImpl.getInstance();
     try {
       final int size = InternalDataSerializer.readArrayLength(in);
       if (cache != null && size > 0) {
@@ -129,6 +139,7 @@ public class TXRegionLockRequestImpl implements TXRegionLockRequest {
     return set;
   }
 
+  @Override
   public void toData(DataOutput out) throws IOException {
     DataSerializer.writeString(getRegionFullPath(), out);
     InternalDataSerializer.writeSet(this.entryKeys, out);
@@ -141,6 +152,7 @@ public class TXRegionLockRequestImpl implements TXRegionLockRequest {
     return result;
   }
 
+  @Override
   public String getRegionFullPath() {
     if (this.regionPath == null) {
       this.regionPath = this.r.getFullPath();
@@ -148,28 +160,15 @@ public class TXRegionLockRequestImpl implements TXRegionLockRequest {
     return this.regionPath;
   }
 
+  @Override
   public Set<Object> getKeys() {
     if (this.entryKeys == null) {
       // check for cache closed/closing
-      getCache(true);
+      cache.getCancelCriterion().checkCancelInProgress(null);
     }
     return this.entryKeys;
   }
 
-  private InternalCache getCache(boolean throwIfClosing) {
-    final InternalCache cache = GemFireCacheImpl.getInstance();
-    if (cache != null && !cache.isClosed()) {
-      if (throwIfClosing) {
-        cache.getCancelCriterion().checkCancelInProgress(null);
-      }
-      return cache;
-    }
-    if (throwIfClosing) {
-      throw cache.getCacheClosedException("The cache is closed.", null);
-    }
-    return null;
-  }
-
   /**
    * Only safe to call in the vm that creates this request. Once it is serialized this method will
    * return null.
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/TXRegionState.java b/geode-core/src/main/java/org/apache/geode/internal/cache/TXRegionState.java
index 7d16574..20febe9 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/TXRegionState.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/TXRegionState.java
@@ -222,7 +222,7 @@ public class TXRegionState {
     final boolean distributedTX = !byPassDLock && r.getScope().isDistributedAck();
     if (this.uaMods != null || (!distributedTX && this.entryMods.size() > 0)) {
       // need some local locks
-      TXRegionLockRequestImpl rlr = new TXRegionLockRequestImpl(r);
+      TXRegionLockRequestImpl rlr = new TXRegionLockRequestImpl(r.getCache(), r);
       if (this.uaMods != null) {
         rlr.addEntryKeys(this.uaMods.keySet());
       }
@@ -235,7 +235,7 @@ public class TXRegionState {
     }
     if (distributedTX && this.entryMods.size() > 0) {
       // need some distributed locks
-      TXRegionLockRequestImpl rlr = new TXRegionLockRequestImpl(r);
+      TXRegionLockRequestImpl rlr = new TXRegionLockRequestImpl(r.getCache(), r);
       rlr.addEntryKeys(getLockRequestEntryKeys());
       if (!rlr.isEmpty()) {
         req.setOtherMembers(this.otherMembers);
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/TXStateProxyImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/TXStateProxyImpl.java
index 7e0fea4..d33c171 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/TXStateProxyImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/TXStateProxyImpl.java
@@ -121,7 +121,8 @@ public class TXStateProxyImpl implements TXStateProxy {
       } else {
         // Code to keep going forward
         if (r.hasServerProxy()) {
-          this.realDeal = new ClientTXStateStub(this, target, r);
+          this.realDeal =
+              new ClientTXStateStub(r.getCache(), r.getDistributionManager(), this, target, r);
           if (r.scope.isDistributed()) {
             if (txDistributedClientWarningIssued.compareAndSet(false, true)) {
               logger.warn(LocalizedMessage.create(
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tx/ClientTXStateStub.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tx/ClientTXStateStub.java
index 2c52538..f0a3871 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tx/ClientTXStateStub.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tx/ClientTXStateStub.java
@@ -32,10 +32,8 @@ import org.apache.geode.cache.client.internal.ServerRegionProxy;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.distributed.internal.DistributionConfig;
 import org.apache.geode.distributed.internal.DistributionManager;
-import org.apache.geode.distributed.internal.InternalDistributedSystem;
 import org.apache.geode.distributed.internal.ServerLocation;
 import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.internal.cache.LocalRegion;
 import org.apache.geode.internal.cache.TXCommitMessage;
@@ -54,19 +52,6 @@ public class ClientTXStateStub extends TXStateStub {
   /** test hook - used to find out what operations were performed in the last tx */
   private static ThreadLocal<List<TransactionalOperation>> recordedTransactionalOperations = null;
 
-  private final ServerRegionProxy firstProxy;
-
-  private ServerLocation serverAffinityLocation;
-
-  /** the operations performed in the current transaction are held in this list */
-  private List<TransactionalOperation> recordedOperations =
-      Collections.synchronizedList(new LinkedList<TransactionalOperation>());
-
-  /** lock request for obtaining local locks */
-  private TXLockRequest lockReq;
-
-  private Runnable internalAfterLocalLocks;
-
   /**
    * System property to disable conflict checks on clients.
    */
@@ -80,6 +65,21 @@ public class ClientTXStateStub extends TXStateStub {
     return !DISABLE_CONFLICT_CHECK_ON_CLIENT || recordedTransactionalOperations != null;
   }
 
+  private final ServerRegionProxy firstProxy;
+  private final InternalCache cache;
+  private final DistributionManager dm;
+
+  /** the operations performed in the current transaction are held in this list */
+  private final List<TransactionalOperation> recordedOperations =
+      Collections.synchronizedList(new LinkedList<TransactionalOperation>());
+
+  private ServerLocation serverAffinityLocation;
+
+  /** lock request for obtaining local locks */
+  private TXLockRequest lockReq;
+
+  private Runnable internalAfterLocalLocks;
+
   private boolean txRolledback = false;
 
   /**
@@ -92,10 +92,12 @@ public class ClientTXStateStub extends TXStateStub {
     recordedTransactionalOperations = t;
   }
 
-  public ClientTXStateStub(TXStateProxy stateProxy, DistributedMember target,
-      LocalRegion firstRegion) {
+  public ClientTXStateStub(InternalCache cache, DistributionManager dm, TXStateProxy stateProxy,
+      DistributedMember target, LocalRegion firstRegion) {
     super(stateProxy, target);
-    firstProxy = firstRegion.getServerProxy();
+    this.cache = cache;
+    this.dm = dm;
+    this.firstProxy = firstRegion.getServerProxy();
     this.firstProxy.getPool().setupServerAffinity(true);
     if (recordedTransactionalOperations != null) {
       recordedTransactionalOperations.set(this.recordedOperations);
@@ -116,19 +118,26 @@ public class ClientTXStateStub extends TXStateStub {
     }
   }
 
+  TXLockRequest createTXLockRequest() {
+    return new TXLockRequest();
+  }
+
+  TXRegionLockRequestImpl createTXRegionLockRequestImpl(InternalCache cache, LocalRegion region) {
+    return new TXRegionLockRequestImpl(cache, region);
+  }
+
   /**
    * Lock the keys in a local transaction manager
    *
    * @throws CommitConflictException if the key is already locked by some other transaction
    */
   private void obtainLocalLocks() {
-    lockReq = new TXLockRequest();
-    InternalCache cache = GemFireCacheImpl.getExisting("");
+    lockReq = createTXLockRequest();
     for (TransactionalOperation txOp : this.recordedOperations) {
       if (ServerRegionOperation.lockKeyForTx(txOp.getOperation())) {
         TXRegionLockRequest rlr = lockReq.getRegionLockRequest(txOp.getRegionName());
         if (rlr == null) {
-          rlr = new TXRegionLockRequestImpl(cache.getRegionByPath(txOp.getRegionName()));
+          rlr = createTXRegionLockRequestImpl(cache, cache.getRegionByPath(txOp.getRegionName()));
           lockReq.addLocalRequest(rlr);
         }
         if (txOp.getOperation() == ServerRegionOperation.PUT_ALL
@@ -159,14 +168,12 @@ public class ClientTXStateStub extends TXStateStub {
       this.internalAfterSendCommit.run();
     }
 
-    InternalCache cache = GemFireCacheImpl.getInstance();
     if (cache == null) {
+      // we can probably delete this block because cache is now a final var
       // fixes bug 42933
       return;
     }
     cache.getCancelCriterion().checkCancelInProgress(null);
-    InternalDistributedSystem ds = cache.getInternalDistributedSystem();
-    DistributionManager dm = ds.getDistributionManager();
 
     txcm.setDM(dm);
     txcm.setAckRequired(false);
@@ -247,6 +254,7 @@ public class ClientTXStateStub extends TXStateStub {
     }
   }
 
+  @Override
   public InternalDistributedMember getOriginatingMember() {
     /*
      * Client member id is implied from the connection so we don't need this
@@ -254,6 +262,7 @@ public class ClientTXStateStub extends TXStateStub {
     return null;
   }
 
+  @Override
   public boolean isMemberIdForwardingRequired() {
     /*
      * Client member id is implied from the connection so we don't need this Forwarding will occur
@@ -262,11 +271,13 @@ public class ClientTXStateStub extends TXStateStub {
     return false;
   }
 
+  @Override
   public TXCommitMessage getCommitMessage() {
     /* client gets the txcommit message during Op processing and doesn't need it here */
     return null;
   }
 
+  @Override
   public void suspend() {
     this.serverAffinityLocation = this.firstProxy.getPool().getServerAffinityLocation();
     this.firstProxy.getPool().releaseServerAffinity();
@@ -276,6 +287,7 @@ public class ClientTXStateStub extends TXStateStub {
     }
   }
 
+  @Override
   public void resume() {
     this.firstProxy.getPool().setupServerAffinity(true);
     this.firstProxy.getPool().setServerAffinityLocation(this.serverAffinityLocation);
@@ -288,6 +300,7 @@ public class ClientTXStateStub extends TXStateStub {
   /**
    * test hook - maintain a list of tx operations
    */
+  @Override
   public void recordTXOperation(ServerRegionDataAccess region, ServerRegionOperation op, Object key,
       Object arguments[]) {
     if (ClientTXStateStub.transactionRecordingEnabled()) {
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tx/DistClientTXStateStub.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tx/DistClientTXStateStub.java
index 6356f7a..1464124 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tx/DistClientTXStateStub.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tx/DistClientTXStateStub.java
@@ -25,24 +25,16 @@ import org.apache.geode.internal.cache.DistTXCommitMessage;
 import org.apache.geode.internal.cache.DistTXCoordinatorInterface;
 import org.apache.geode.internal.cache.DistTXPrecommitMessage;
 import org.apache.geode.internal.cache.DistTXRollbackMessage;
+import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.internal.cache.LocalRegion;
 import org.apache.geode.internal.cache.TXStateProxy;
 import org.apache.geode.internal.i18n.LocalizedStrings;
 
-/**
- *
- */
 public class DistClientTXStateStub extends ClientTXStateStub implements DistTXCoordinatorInterface {
 
-  /**
-   * @param stateProxy
-   * @param target
-   * @param firstRegion
-   */
-  public DistClientTXStateStub(TXStateProxy stateProxy, DistributedMember target,
-      LocalRegion firstRegion) {
-    super(stateProxy, target, firstRegion);
-    // TODO Auto-generated constructor stub
+  public DistClientTXStateStub(InternalCache cache, DistributionManager dm, TXStateProxy stateProxy,
+      DistributedMember target, LocalRegion firstRegion) {
+    super(cache, dm, stateProxy, target, firstRegion);
   }
 
   @Override
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/TXRegionLockRequestImplTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/TXRegionLockRequestImplTest.java
new file mode 100644
index 0000000..19cb5b8
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/TXRegionLockRequestImplTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.geode.internal.cache;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.CancelCriterion;
+import org.apache.geode.CancelException;
+import org.apache.geode.cache.CacheClosedException;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class TXRegionLockRequestImplTest {
+
+  private InternalCache cache;
+  private LocalRegion region;
+  private CancelCriterion cancelCriterion;
+
+  @Before
+  public void setUp() {
+    cache = mock(InternalCache.class);
+    region = mock(LocalRegion.class);
+    cancelCriterion = mock(CancelCriterion.class);
+
+    when(cache.getCancelCriterion()).thenReturn(cancelCriterion);
+    doThrow(new CacheClosedException()).when(cancelCriterion).checkCancelInProgress(any());
+  }
+
+  @Test
+  public void getKeysThrowsCancelExceptionIfCacheIsClosed() {
+    TXRegionLockRequestImpl txRegionLockRequest = new TXRegionLockRequestImpl(cache, region);
+    assertThatThrownBy(() -> txRegionLockRequest.getKeys()).isInstanceOf(CancelException.class);
+  }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/TXReservationMgrJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/TXReservationMgrJUnitTest.java
index 6a9072a..90d1574 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/TXReservationMgrJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/TXReservationMgrJUnitTest.java
@@ -70,7 +70,7 @@ public class TXReservationMgrJUnitTest {
       do {
         try {
           IdentityArrayList l = new IdentityArrayList(1);
-          TXRegionLockRequestImpl lr = new TXRegionLockRequestImpl(this.r);
+          TXRegionLockRequestImpl lr = new TXRegionLockRequestImpl(this.r.getCache(), this.r);
           lr.addEntryKeys(Collections.singleton(key));
           l.add(lr);
           mgr.makeReservation(l);
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tx/ClientTXStateStubTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tx/ClientTXStateStubTest.java
new file mode 100644
index 0000000..e6336ef
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tx/ClientTXStateStubTest.java
@@ -0,0 +1,82 @@
+/*
+ * 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.geode.internal.cache.tx;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.CancelCriterion;
+import org.apache.geode.CancelException;
+import org.apache.geode.cache.CacheClosedException;
+import org.apache.geode.cache.client.internal.InternalPool;
+import org.apache.geode.cache.client.internal.ServerRegionProxy;
+import org.apache.geode.distributed.DistributedMember;
+import org.apache.geode.distributed.internal.DistributionManager;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.LocalRegion;
+import org.apache.geode.internal.cache.TXId;
+import org.apache.geode.internal.cache.TXLockRequest;
+import org.apache.geode.internal.cache.TXRegionLockRequestImpl;
+import org.apache.geode.internal.cache.TXStateProxy;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class ClientTXStateStubTest {
+
+  private InternalCache cache;
+  private DistributionManager dm;
+  private TXStateProxy stateProxy;
+  private DistributedMember target;
+  private LocalRegion region;
+  private ServerRegionProxy serverRegionProxy;
+  private CancelCriterion cancelCriterion;
+
+  @Before
+  public void setUp() {
+    cache = mock(InternalCache.class);
+    dm = mock(DistributionManager.class);
+    stateProxy = mock(TXStateProxy.class);
+    target = mock(DistributedMember.class);
+    region = mock(LocalRegion.class);
+    serverRegionProxy = mock(ServerRegionProxy.class);
+    cancelCriterion = mock(CancelCriterion.class);
+
+    when(region.getServerProxy()).thenReturn(serverRegionProxy);
+    when(serverRegionProxy.getPool()).thenReturn(mock(InternalPool.class));
+    when(stateProxy.getTxId()).thenReturn(mock(TXId.class));
+    when(cache.getCancelCriterion()).thenReturn(cancelCriterion);
+    doThrow(new CacheClosedException()).when(cancelCriterion).checkCancelInProgress(any());
+  }
+
+  @Test
+  public void commitThrowsCancelExceptionIfCacheIsClosed() {
+    ClientTXStateStub stub = spy(new ClientTXStateStub(cache, dm, stateProxy, target, region));
+
+    when(stub.createTXLockRequest()).thenReturn(mock(TXLockRequest.class));
+    when(stub.createTXRegionLockRequestImpl(any(), any()))
+        .thenReturn(mock(TXRegionLockRequestImpl.class));
+
+    assertThatThrownBy(() -> stub.commit()).isInstanceOf(CancelException.class);
+  }
+
+}

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].