private EntityRef<ClusterTierManagerClientEntity, ClusterTierManagerConfiguration, ClusterTierUserData> getEntityRef(String identifier) { try { return connection.getEntityRef(ClusterTierManagerClientEntity.class, ENTITY_VERSION, identifier); } catch (EntityNotProvidedException e) { LOGGER.error("Unable to get cluster tier manager for id {}", identifier, e); throw new AssertionError(e); } }
private EntityRef<E, C, U> getEntityRef() { try { return getConnection().getEntityRef(entityType, entityVersion, entityIdentifier); } catch (EntityNotProvidedException e) { LOGGER.error("Unable to find reference for entity {} for id {}", entityType.getName(), entityIdentifier, e); throw new AssertionError(e); } }
public ClusterTierClientEntity getClusterTierClientEntity(String clusterTierManagerIdentifier, String storeIdentifier) throws EntityNotFoundException { EntityRef<InternalClusterTierClientEntity, ClusterTierEntityConfiguration, ClusterTierUserData> entityRef; try { entityRef = connection.getEntityRef(InternalClusterTierClientEntity.class, ENTITY_VERSION, entityName(clusterTierManagerIdentifier, storeIdentifier)); } catch (EntityNotProvidedException e) { throw new AssertionError(e); } return fetchClusterTierClientEntity(storeIdentifier, entityRef); }
public void destroyClusteredStoreEntity(String clusterTierManagerIdentifier, String storeIdentifier) throws EntityNotFoundException, CachePersistenceException { EntityRef<InternalClusterTierClientEntity, ClusterTierEntityConfiguration, Void> entityRef; try { entityRef = connection.getEntityRef(InternalClusterTierClientEntity.class, ENTITY_VERSION, entityName(clusterTierManagerIdentifier, storeIdentifier)); if (!entityRef.destroy()) { throw new CachePersistenceException("Cannot destroy cluster tier '" + storeIdentifier + "': in use by other client(s)"); } } catch (EntityNotProvidedException | PermanentEntityException e) { throw new AssertionError(e); } }
private <E extends Entity> EntityRef<E, Object, Void> getEntityRef(Class<E> value) throws org.terracotta.exception.EntityNotProvidedException { return connection.getEntityRef(same(value), eq(ENTITY_VERSION), any()); } }
private EntityRef<ClusterTierManagerClientEntity, ClusterTierManagerConfiguration, Void> getEntityRef(Connection client) throws org.terracotta.exception.EntityNotProvidedException { return client.getEntityRef(ClusterTierManagerClientEntity.class, EhcacheEntityVersion.ENTITY_VERSION, testName.getMethodName()); } }
private void mockLockForWriteLockSuccess() throws org.terracotta.exception.EntityNotProvidedException, org.terracotta.exception.EntityNotFoundException, org.terracotta.exception.EntityVersionMismatchException { when(connection.<VoltronReadWriteLockClient, Object, Void>getEntityRef(same(VoltronReadWriteLockClient.class), eq(1L), any())).thenReturn(lockEntityRef); VoltronReadWriteLockClient lockClient = mock(VoltronReadWriteLockClient.class); when(lockEntityRef.fetchEntity(null)).thenReturn(lockClient); when(lockClient.tryLock(LockMessaging.HoldType.WRITE)).thenReturn(true); }
private void mockLockForReadLockSuccess() throws org.terracotta.exception.EntityNotProvidedException, org.terracotta.exception.EntityNotFoundException, org.terracotta.exception.EntityVersionMismatchException { when(connection.<VoltronReadWriteLockClient, Object, Void>getEntityRef(same(VoltronReadWriteLockClient.class), eq(1L), any())).thenReturn(lockEntityRef); VoltronReadWriteLockClient lockClient = mock(VoltronReadWriteLockClient.class); when(lockEntityRef.fetchEntity(null)).thenReturn(lockClient); when(lockClient.tryLock(LockMessaging.HoldType.READ)).thenReturn(true); }
private static void addMockLock(Connection connection, String lockname, boolean result, Boolean ... results) throws Exception { VoltronReadWriteLockClient lock = mock(VoltronReadWriteLockClient.class); when(lock.tryLock(any(HoldType.class))).thenReturn(result, results); @SuppressWarnings("unchecked") EntityRef<VoltronReadWriteLockClient, Object, Object> interlockRef = mock(EntityRef.class); when(connection.getEntityRef(eq(VoltronReadWriteLockClient.class), anyLong(), eq(lockname))).thenReturn(interlockRef); when(interlockRef.fetchEntity(null)).thenReturn(lock); }
@Test public void testReadLockLocksRead() throws Exception { when(entityRef.fetchEntity(null)).thenReturn(client); when(connection.<VoltronReadWriteLockClient, Void, Void>getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-TestLock")).thenReturn(entityRef); VoltronReadWriteLock lock = new VoltronReadWriteLock(connection, "TestLock"); lock.readLock(); verify(client).lock(READ); }
@Test public void testTryWriteUnlockUnlocksWrite() throws Exception { when(client.tryLock(WRITE)).thenReturn(true); when(entityRef.fetchEntity(null)).thenReturn(client); when(connection.<VoltronReadWriteLockClient, Void, Void>getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-TestLock")).thenReturn(entityRef); VoltronReadWriteLock lock = new VoltronReadWriteLock(connection, "TestLock"); lock.tryWriteLock().unlock(); verify(client).unlock(WRITE); }
@Test public void testTryWriteUnlockDestroysEntity() throws Exception { when(client.tryLock(WRITE)).thenReturn(true); when(entityRef.fetchEntity(null)).thenReturn(client); when(connection.<VoltronReadWriteLockClient, Void, Void>getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-TestLock")).thenReturn(entityRef); VoltronReadWriteLock lock = new VoltronReadWriteLock(connection, "TestLock"); lock.tryWriteLock().unlock(); verify(entityRef).destroy(); }
@Test public void testWriteUnlockDestroysEntity() throws Exception { when(entityRef.fetchEntity(null)).thenReturn(client); when(connection.<VoltronReadWriteLockClient, Void, Void>getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-TestLock")).thenReturn(entityRef); VoltronReadWriteLock lock = new VoltronReadWriteLock(connection, "TestLock"); lock.writeLock().unlock(); verify(entityRef).destroy(); }
@Test public void testTryReadUnlockClosesEntity() throws Exception { when(client.tryLock(READ)).thenReturn(true); when(entityRef.fetchEntity(null)).thenReturn(client); when(connection.<VoltronReadWriteLockClient, Void, Void>getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-TestLock")).thenReturn(entityRef); VoltronReadWriteLock lock = new VoltronReadWriteLock(connection, "TestLock"); lock.tryReadLock().unlock(); verify(client).close(); }
@Test public void testTryWriteLockFailingDestroysEntity() throws Exception { when(client.tryLock(WRITE)).thenReturn(false); when(entityRef.fetchEntity(null)).thenReturn(client); when(connection.<VoltronReadWriteLockClient, Void, Void>getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-TestLock")).thenReturn(entityRef); VoltronReadWriteLock lock = new VoltronReadWriteLock(connection, "TestLock"); assertThat(lock.tryWriteLock(), nullValue()); verify(entityRef).destroy(); }
@Test public void testTryReadLockTryLocksRead() throws Exception { when(client.tryLock(READ)).thenReturn(true); when(entityRef.fetchEntity(null)).thenReturn(client); when(connection.<VoltronReadWriteLockClient, Void, Void>getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-TestLock")).thenReturn(entityRef); VoltronReadWriteLock lock = new VoltronReadWriteLock(connection, "TestLock"); assertThat(lock.tryReadLock(), notNullValue()); verify(client).tryLock(READ); }
@Test public void testTryWriteLockFailingClosesEntity() throws Exception { when(client.tryLock(WRITE)).thenReturn(false); when(entityRef.fetchEntity(null)).thenReturn(client); when(connection.<VoltronReadWriteLockClient, Void, Void>getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-TestLock")).thenReturn(entityRef); VoltronReadWriteLock lock = new VoltronReadWriteLock(connection, "TestLock"); assertThat(lock.tryWriteLock(), nullValue()); verify(client).close(); }
@Test public void testTryReadLockFailingDestroysEntity() throws Exception { when(client.tryLock(READ)).thenReturn(false); when(entityRef.fetchEntity(null)).thenReturn(client); when(connection.<VoltronReadWriteLockClient, Void, Void>getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-TestLock")).thenReturn(entityRef); VoltronReadWriteLock lock = new VoltronReadWriteLock(connection, "TestLock"); assertThat(lock.tryReadLock(), nullValue()); verify(entityRef).destroy(); } }
@Test public void testCreateLockEntityWhenNotExisting() throws Exception { when(entityRef.fetchEntity(null)).thenReturn(client); when(connection.<VoltronReadWriteLockClient, Void, Void>getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-TestLock")).thenReturn(entityRef); VoltronReadWriteLock lock = new VoltronReadWriteLock(connection, "TestLock"); lock.readLock(); verify(entityRef).create(isNull()); }
@Test public void testWriteUnlockClosesEntity() throws Exception { when(entityRef.fetchEntity(null)).thenReturn(client); when(connection.<VoltronReadWriteLockClient, Void, Void>getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-TestLock")).thenReturn(entityRef); VoltronReadWriteLock lock = new VoltronReadWriteLock(connection, "TestLock"); lock.writeLock().unlock(); verify(client).close(); }