@Test public void testLoadExistingRegistersEvictionListener() throws Exception { EhcacheStateService stateService = mock(EhcacheStateService.class); ServerSideServerStore store = mock(ServerSideServerStore.class); when(stateService.loadStore(eq(defaultStoreName), any())).thenReturn(store); IEntityMessenger<EhcacheEntityMessage, EhcacheEntityResponse> entityMessenger = mock(IEntityMessenger.class); ServiceRegistry registry = getCustomMockedServiceRegistry(stateService, null, entityMessenger, null, null); ClusterTierActiveEntity activeEntity = new ClusterTierActiveEntity(registry, defaultConfiguration, DEFAULT_MAPPER); activeEntity.loadExisting(); verify(store).setEvictionListener(any(ServerStoreEvictionListener.class)); }
@Test(expected = ConfigurationException.class) public void testConfigNull() throws Exception { new ClusterTierActiveEntity(mock(ServiceRegistry.class), null, DEFAULT_MAPPER); }
@Test public void testDataSyncToPassiveCustomGets() throws Exception { System.setProperty(ClusterTierActiveEntity.SYNC_DATA_GETS_PROP, "2"); try { prepareAndRunActiveEntityForPassiveSync((activeEntity, concurrencyKey) -> { @SuppressWarnings("unchecked") PassiveSynchronizationChannel<EhcacheEntityMessage> syncChannel = mock(PassiveSynchronizationChannel.class); activeEntity.synchronizeKeyToPassive(syncChannel, concurrencyKey); verify(syncChannel, atLeast(2)).synchronizeToPassive(any(EhcacheDataSyncMessage.class)); }); } finally { System.clearProperty(ClusterTierActiveEntity.SYNC_DATA_GETS_PROP); } }
@Test public void testDataSyncToPassiveCustomBatchSize() throws Exception { System.setProperty(ClusterTierActiveEntity.SYNC_DATA_SIZE_PROP, "512"); try { prepareAndRunActiveEntityForPassiveSync((activeEntity, concurrencyKey) -> { @SuppressWarnings("unchecked") PassiveSynchronizationChannel<EhcacheEntityMessage> syncChannel = mock(PassiveSynchronizationChannel.class); activeEntity.synchronizeKeyToPassive(syncChannel, concurrencyKey); verify(syncChannel, atLeast(2)).synchronizeToPassive(any(EhcacheDataSyncMessage.class)); }); } finally { System.clearProperty(ClusterTierActiveEntity.SYNC_DATA_SIZE_PROP); } }
@Test public void testDataSyncToPassiveException() throws Exception { System.setProperty(ClusterTierActiveEntity.SYNC_DATA_GETS_PROP, "1"); try { prepareAndRunActiveEntityForPassiveSync((activeEntity, concurrencyKey) -> { @SuppressWarnings("unchecked") PassiveSynchronizationChannel<EhcacheEntityMessage> syncChannel = mock(PassiveSynchronizationChannel.class); activeEntity.destroy(); try { activeEntity.synchronizeKeyToPassive(syncChannel, concurrencyKey); fail("Destroyed entity not expected to sync"); } catch (RuntimeException e) { assertThat(e.getCause(), instanceOf(ExecutionException.class)); } }); } finally { System.clearProperty(ClusterTierActiveEntity.SYNC_DATA_GETS_PROP); } }
if (serviceConfiguration.getServiceType().equals(ClientCommunicator.class)) { if (this.clientCommunicator == null) { this.clientCommunicator = mock(ClientCommunicator.class); } else if (serviceConfiguration.getServiceType().equals(IEntityMessenger.class)) { if (this.entityMessenger == null) { this.entityMessenger = mock(IEntityMessenger.class);
@Test public void testSyncToPassiveNoData() throws Exception { ClusterTierActiveEntity activeEntity = new ClusterTierActiveEntity(defaultRegistry, defaultConfiguration, DEFAULT_MAPPER); activeEntity.createNew(); TestInvokeContext context = new TestInvokeContext(); activeEntity.connected(context.getClientDescriptor()); assertSuccess(activeEntity.invokeActive(context, new LifecycleMessage.ValidateServerStore(defaultStoreName, defaultStoreConfiguration))); @SuppressWarnings("unchecked") PassiveSynchronizationChannel<EhcacheEntityMessage> syncChannel = mock(PassiveSynchronizationChannel.class); activeEntity.synchronizeKeyToPassive(syncChannel, 3); verifyZeroInteractions(syncChannel); }
@Test public void testSyncToPassiveBatchedByDefault() throws Exception { ClusterTierActiveEntity activeEntity = new ClusterTierActiveEntity(defaultRegistry, defaultConfiguration, DEFAULT_MAPPER); activeEntity.createNew(); TestInvokeContext context = new TestInvokeContext(); activeEntity.connected(context.getClientDescriptor()); assertSuccess(activeEntity.invokeActive(context, new LifecycleMessage.ValidateServerStore(defaultStoreName, defaultStoreConfiguration))); ByteBuffer payload = ByteBuffer.allocate(512); // Put keys that maps to the same concurrency key assertSuccess(activeEntity.invokeActive(context, new ServerStoreOpMessage.AppendMessage(1L, payload))); assertSuccess(activeEntity.invokeActive(context, new ServerStoreOpMessage.AppendMessage(-2L, payload))); assertSuccess(activeEntity.invokeActive(context, new ServerStoreOpMessage.AppendMessage(17L, payload))); @SuppressWarnings("unchecked") PassiveSynchronizationChannel<EhcacheEntityMessage> syncChannel = mock(PassiveSynchronizationChannel.class); activeEntity.synchronizeKeyToPassive(syncChannel, 3); verify(syncChannel).synchronizeToPassive(any(EhcacheDataSyncMessage.class)); }