private static EntityRef<VoltronReadWriteLockClient, Void, Void> createEntityRef(Connection connection, String identifier) throws EntityNotProvidedException { return connection.getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-" + identifier); } }
public void closeConnection() { Connection conn = clusterConnection; clusterConnection = null; if(conn != null) { try { conn.close(); } catch (IOException | ConnectionShutdownException e) { LOGGER.warn("Error closing cluster connection: " + e); } } }
private Connection getConnection() throws ConnectionException { if (mockConnection == null) { throw new ConnectionException(new IllegalStateException("Set mock connection first")); } return mockConnection; } }
private static <T extends Entity> void fetchEntity(Connection connection, Class<T> aClass, String myCacheManager) throws EntityNotFoundException, ConnectionException { try { connection.getEntityRef(aClass, EhcacheEntityVersion.ENTITY_VERSION, myCacheManager).fetchEntity(null).close(); } catch (EntityNotProvidedException | EntityVersionMismatchException e) { throw new AssertionError(e); } }
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); }
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 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 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); } }
@AfterClass public static void closeConnection() throws IOException { CONNECTION.close(); }
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); }
private EntityRef<ClusterTierManagerClientEntity, ClusterTierManagerConfiguration, Void> getEntityRef(Connection client) throws org.terracotta.exception.EntityNotProvidedException { return client.getEntityRef(ClusterTierManagerClientEntity.class, ENTITY_VERSION, "crud-cm"); } }
@AfterClass public static void closeAssertionConnection() throws IOException { ASSERTION_CONNECTION.close(); }
@Override public<T extends Entity, C, U> EntityRef<T, C, U> getEntityRef(Class<T> cls, long version, String name) throws EntityNotProvidedException { return ASSERTION_CONNECTION.getEntityRef(cls, version, name); }
public static void removeStripe(String stripeName) { StripeDescriptor stripeDescriptor = STRIPES.remove(stripeName); for (Connection connection : stripeDescriptor.getConnections()) { try { LOGGER.warn("Force close {}", formatConnectionId(connection)); connection.close(); } catch (IllegalStateException | IOException e) { // Ignored in case connection is already closed } } stripeDescriptor.removeConnections(); }
private EntityRef<VoltronReadWriteLockClient, Void, Void> getEntityReference(Connection connection) throws EntityNotProvidedException { return connection.getEntityRef(VoltronReadWriteLockClient.class, 1, "TestEntity"); }
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); }
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 <E extends Entity> EntityRef<E, Object, Void> getEntityRef(Class<E> value) throws org.terracotta.exception.EntityNotProvidedException { return connection.getEntityRef(eq(value), anyLong(), anyString()); } }