|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license |
| 3 | + * agreements. See the NOTICE file distributed with this work for additional information regarding |
| 4 | + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the |
| 5 | + * "License"); you may not use this file except in compliance with the License. You may obtain a |
| 6 | + * copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 11 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 12 | + * or implied. See the License for the specific language governing permissions and limitations under |
| 13 | + * the License. |
| 14 | + */ |
| 15 | + |
| 16 | +package org.apache.geode.internal.cache.locks; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
| 19 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 20 | +import static org.mockito.Mockito.mock; |
| 21 | +import static org.mockito.Mockito.when; |
| 22 | + |
| 23 | +import java.util.ArrayList; |
| 24 | +import java.util.List; |
| 25 | +import java.util.Set; |
| 26 | + |
| 27 | +import org.junit.Before; |
| 28 | +import org.junit.Test; |
| 29 | + |
| 30 | +import org.apache.geode.cache.CommitConflictException; |
| 31 | +import org.apache.geode.distributed.internal.DistributionManager; |
| 32 | +import org.apache.geode.distributed.internal.InternalDistributedSystem; |
| 33 | +import org.apache.geode.distributed.internal.locks.DLockService; |
| 34 | +import org.apache.geode.distributed.internal.membership.InternalDistributedMember; |
| 35 | +import org.apache.geode.internal.util.concurrent.StoppableReentrantReadWriteLock; |
| 36 | + |
| 37 | +public class TXLockServiceImplTest { |
| 38 | + private TXLockServiceImpl txLockService; |
| 39 | + private InternalDistributedSystem internalDistributedSystem; |
| 40 | + private DLockService dlock; |
| 41 | + private List distLocks; |
| 42 | + private Set otherMembers; |
| 43 | + private DistributionManager distributionManager; |
| 44 | + private InternalDistributedMember distributedMember; |
| 45 | + private StoppableReentrantReadWriteLock recoverylock; |
| 46 | + |
| 47 | + @Before |
| 48 | + public void setUp() { |
| 49 | + internalDistributedSystem = mock(InternalDistributedSystem.class); |
| 50 | + dlock = mock(DLockService.class); |
| 51 | + distributionManager = mock(DistributionManager.class); |
| 52 | + distributedMember = mock(InternalDistributedMember.class); |
| 53 | + recoverylock = mock(StoppableReentrantReadWriteLock.class); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void testTxLockService() { |
| 58 | + distLocks = new ArrayList(); |
| 59 | + txLockService = new TXLockServiceImpl(internalDistributedSystem, recoverylock, dlock); |
| 60 | + |
| 61 | + when(dlock.getDistributionManager()).thenReturn(distributionManager); |
| 62 | + when(dlock.getDistributionManager().getId()).thenReturn(distributedMember); |
| 63 | + |
| 64 | + assertThat((txLockService).getTxLockIdList()).isEqualTo(0); |
| 65 | + |
| 66 | + assertThrows(CommitConflictException.class, |
| 67 | + () -> txLockService.txLock(distLocks, otherMembers)); |
| 68 | + |
| 69 | + assertThat((txLockService).getTxLockIdList()).isEqualTo(0); |
| 70 | + } |
| 71 | +} |
0 commit comments