@Test public void postProcessWhenEnvironmentAwareThenAwareInvoked() { this.spring.register(Config.class).autowire(); EnvironmentAware toPostProcess = mock(EnvironmentAware.class); this.objectObjectPostProcessor.postProcess(toPostProcess); verify(toPostProcess).setEnvironment(isNotNull()); }
@Test public void postProcessWhenApplicationEventPublisherAwareThenAwareInvoked() { this.spring.register(Config.class).autowire(); ApplicationEventPublisherAware toPostProcess = mock(ApplicationEventPublisherAware.class); this.objectObjectPostProcessor.postProcess(toPostProcess); verify(toPostProcess).setApplicationEventPublisher(isNotNull()); }
@Test public void postProcessWhenMessageSourceAwareThenAwareInvoked() { this.spring.register(Config.class).autowire(); MessageSourceAware toPostProcess = mock(MessageSourceAware.class); this.objectObjectPostProcessor.postProcess(toPostProcess); verify(toPostProcess).setMessageSource(isNotNull()); }
@Test public void whenNoMembersFoundAndClusterConfigRunningThenUpdateClusterConfig() { InternalConfigurationPersistenceService clusterConfigService = mock(InternalConfigurationPersistenceService.class); CacheConfig cacheConfig = mock(CacheConfig.class); doReturn(Collections.emptySet()).when(command).findMembers(any(), any()); doReturn(clusterConfigService).when(command).getConfigurationPersistenceService(); doReturn(cacheConfig).when(clusterConfigService).getCacheConfig(any()); doAnswer(invocation -> { UnaryOperator<CacheConfig> mutator = invocation.getArgument(1); mutator.apply(cacheConfig); return null; }).when(clusterConfigService).updateCacheConfig(any(), any()); gfsh.executeAndAssertThat(command, COMMAND + " --name=name --url=url") .statusIsSuccess() .containsOutput("No members found, data source saved to cluster configuration.") .containsOutput("Changes to configuration for group 'cluster' are persisted."); verify(clusterConfigService).updateCacheConfig(any(), any()); verify(command).updateConfigForGroup(eq("cluster"), eq(cacheConfig), isNotNull()); }
@Test public void postProcessWhenServletContextAwareThenAwareInvoked() { this.spring.register(Config.class).autowire(); ServletContextAware toPostProcess = mock(ServletContextAware.class); this.objectObjectPostProcessor.postProcess(toPostProcess); verify(toPostProcess).setServletContext(isNotNull()); }
@Test public void postProcessWhenApplicationContextAwareThenAwareInvoked() { this.spring.register(Config.class).autowire(); ApplicationContextAware toPostProcess = mock(ApplicationContextAware.class); this.objectObjectPostProcessor.postProcess(toPostProcess); verify(toPostProcess).setApplicationContext(isNotNull()); }
@Test public void postProcessWhenBeanClassLoaderAwareThenAwareInvoked() { this.spring.register(Config.class).autowire(); BeanClassLoaderAware toPostProcess = mock(BeanClassLoaderAware.class); this.objectObjectPostProcessor.postProcess(toPostProcess); verify(toPostProcess).setBeanClassLoader(isNotNull()); }
@Test public void postProcessWhenBeanFactoryAwareThenAwareInvoked() { this.spring.register(Config.class).autowire(); BeanFactoryAware toPostProcess = mock(BeanFactoryAware.class); this.objectObjectPostProcessor.postProcess(toPostProcess); verify(toPostProcess).setBeanFactory(isNotNull()); }
@Test public void whenNoMembersFoundAndClusterConfigRunningThenUpdateClusterConfig() { List<JndiBindingsType.JndiBinding> bindings = new ArrayList<>(); JndiBindingsType.JndiBinding jndiBinding = new JndiBindingsType.JndiBinding(); jndiBinding.setJndiName("name"); jndiBinding.setType(CreateJndiBindingCommand.DATASOURCE_TYPE.SIMPLE.getType()); bindings.add(jndiBinding); doReturn(bindings).when(cacheConfig).getJndiBindings(); gfsh.executeAndAssertThat(command, COMMAND + " --name=name").statusIsSuccess() .containsOutput("No members found, data source removed from cluster configuration.") .containsOutput("Changes to configuration for group 'cluster' are persisted."); verify(ccService).updateCacheConfig(any(), any()); verify(command).updateConfigForGroup(eq("cluster"), eq(cacheConfig), isNotNull()); }
@Test public void announcesProgressToPersistenceAdvisor_whenWaitingForMissingMembers() { persistenceInitialImageAdvisor = persistenceInitialImageAdvisorWithDiskImage(); setMembershipChangePollDuration(Duration.ofSeconds(0)); HashSet<PersistentMemberID> offlineMembersToWaitFor = memberIDs("offline member", 1); Set<PersistentMemberID> membersToWaitFor = new HashSet<>(offlineMembersToWaitFor); when(persistenceAdvisor.getPersistedOnlineOrEqualMembers()).thenReturn(offlineMembersToWaitFor); when(persistenceAdvisor.getMembersToWaitFor(any(), any())).thenAnswer(invocation -> { Set<PersistentMemberID> offlineMembers = invocation.getArgument(1); offlineMembers.addAll(offlineMembersToWaitFor); return membersToWaitFor; }); when(cacheDistributionAdvisor.adviseInitialImage(null, true)) .thenReturn(adviceWithReplicates(0), adviceWithReplicates(1)); persistenceInitialImageAdvisor.getAdvice(null); InOrder inOrder = inOrder(persistenceAdvisor); inOrder.verify(persistenceAdvisor, times(1)).beginWaitingForMembershipChange(membersToWaitFor); inOrder.verify(persistenceAdvisor, times(1)).setWaitingOnMembers(isNotNull(), eq(offlineMembersToWaitFor)); inOrder.verify(persistenceAdvisor, times(1)).endWaitingForMembershipChange(); inOrder.verify(persistenceAdvisor, times(1)).setWaitingOnMembers(isNull(), isNull()); inOrder.verify(persistenceAdvisor, times(0)).setWaitingOnMembers(any(), any()); }
@Test public void whenNoMembersFoundAndClusterConfigRunningWithPooledTypeThenUpdateClusterConfig() { List<JndiBindingsType.JndiBinding> bindings = new ArrayList<>(); JndiBindingsType.JndiBinding jndiBinding = new JndiBindingsType.JndiBinding(); jndiBinding.setJndiName("name"); jndiBinding.setType(CreateJndiBindingCommand.DATASOURCE_TYPE.POOLED.getType()); bindings.add(jndiBinding); doReturn(bindings).when(cacheConfig).getJndiBindings(); gfsh.executeAndAssertThat(command, COMMAND + " --name=name").statusIsSuccess() .containsOutput("No members found, data source removed from cluster configuration.") .containsOutput("Changes to configuration for group 'cluster' are persisted."); verify(ccService).updateCacheConfig(any(), any()); verify(command).updateConfigForGroup(eq("cluster"), eq(cacheConfig), isNotNull()); }
@Test public void whenNoMembersFoundAndClusterConfigRunningAndRegionUsingOtherDataSourceThenUpdateClusterConfig() { List<JndiBindingsType.JndiBinding> bindings = new ArrayList<>(); JndiBindingsType.JndiBinding jndiBinding = new JndiBindingsType.JndiBinding(); jndiBinding.setJndiName("name"); jndiBinding.setType(CreateJndiBindingCommand.DATASOURCE_TYPE.SIMPLE.getType()); bindings.add(jndiBinding); doReturn(bindings).when(cacheConfig).getJndiBindings(); setupRegionConfigToUseDataSource("otherDataSource"); gfsh.executeAndAssertThat(command, COMMAND + " --name=name").statusIsSuccess() .containsOutput("No members found, data source removed from cluster configuration.") .containsOutput("Changes to configuration for group 'cluster' are persisted."); verify(ccService).updateCacheConfig(any(), any()); verify(command).updateConfigForGroup(eq("cluster"), eq(cacheConfig), isNotNull()); }
@Test public void jsr107LoaderGetsRegistered() { MutableConfiguration<Object, Object> configuration = new MutableConfiguration<>(); CacheLoader<Object, Object> mock = mock(CacheLoader.class); RecordingFactory<CacheLoader<Object, Object>> factory = factoryOf(mock); configuration.setReadThrough(true).setCacheLoaderFactory(factory); merger.mergeConfigurations("cache", configuration); assertThat(factory.called, is(true)); verify(cacheLoaderWriterFactory).registerJsr107Loader(eq("cache"), ArgumentMatchers.<CacheLoaderWriter<Object, Object>>isNotNull()); }
@Test public void jsr107WriterGetsRegistered() { MutableConfiguration<Object, Object> configuration = new MutableConfiguration<>(); CacheWriter<Object, Object> mock = mock(CacheWriter.class); RecordingFactory<CacheWriter<Object, Object>> factory = factoryOf(mock); configuration.setWriteThrough(true).setCacheWriterFactory(factory); merger.mergeConfigurations("cache", configuration); assertThat(factory.called, is(true)); verify(cacheLoaderWriterFactory).registerJsr107Loader(eq("cache"), ArgumentMatchers.<CacheLoaderWriter<Object, Object>>isNotNull()); }
@Test public void obtainsFreshAdvice_ifAdviceIncludesNoReplicatesAndPreviousAdviceHasReplicates() { InitialImageAdvice previousAdviceWithReplicates = adviceWithReplicates(1); persistenceInitialImageAdvisor = persistenceInitialImageAdvisorWithDiskImage(); when(cacheDistributionAdvisor.adviseInitialImage(isNotNull(), anyBoolean())) .thenReturn(adviceWithReplicates(0)); when(cacheDistributionAdvisor.adviseInitialImage(isNull(), anyBoolean())) .thenReturn(adviceWithReplicates(1)); persistenceInitialImageAdvisor.getAdvice(previousAdviceWithReplicates); InOrder inOrder = inOrder(cacheDistributionAdvisor); inOrder.verify(cacheDistributionAdvisor, times(1)) .adviseInitialImage(same(previousAdviceWithReplicates), anyBoolean()); inOrder.verify(cacheDistributionAdvisor, times(1)).adviseInitialImage(isNull(), anyBoolean()); inOrder.verify(cacheDistributionAdvisor, times(0)).adviseInitialImage(any(), anyBoolean()); }
@Test public void testCacheManagerListener_called_after_configuration_updated() throws Exception { EhcacheManager cacheManager = (EhcacheManager) CacheManagerBuilder.newCacheManagerBuilder() .build(); CacheManagerListener cacheManagerListener = spy(new AssertiveCacheManagerListener(cacheManager.getRuntimeConfiguration())); cacheManager.registerListener(cacheManagerListener); cacheManager.init(); CacheConfiguration<String, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class, newResourcePoolsBuilder() .heap(10, EntryUnit.ENTRIES) .offheap(1, MemoryUnit.MB)) .build(); cacheManager.createCache(CACHE_NAME, cacheConfiguration); verify(cacheManagerListener).cacheAdded(eq(CACHE_NAME), (Cache<?, ?>) isNotNull()); cacheManager.removeCache(CACHE_NAME); verify(cacheManagerListener).cacheRemoved(eq(CACHE_NAME), (Cache<?, ?>) isNotNull()); }
@Test @SuppressWarnings("unchecked") public void testReplicationMessageAndOriginalServerStoreOpMessageHasSameConcurrency() throws Exception { ClusterTierActiveEntity activeEntity = new ClusterTierActiveEntity(defaultRegistry, defaultConfiguration, DEFAULT_MAPPER); activeEntity.createNew(); IEntityMessenger<EhcacheEntityMessage, EhcacheEntityResponse> entityMessenger = defaultRegistry.getEntityMessenger(); TestInvokeContext context = new TestInvokeContext(); activeEntity.connected(context.getClientDescriptor()); assertSuccess(activeEntity.invokeActive(context, new LifecycleMessage.ValidateServerStore(defaultStoreName, defaultStoreConfiguration))); reset(entityMessenger); EhcacheEntityMessage getAndAppend = new ServerStoreOpMessage.GetAndAppendMessage(1L, createPayload(1L)); activeEntity.invokeActive(context, getAndAppend); ArgumentCaptor<PassiveReplicationMessage.ChainReplicationMessage> captor = ArgumentCaptor.forClass(PassiveReplicationMessage.ChainReplicationMessage.class); verify(entityMessenger).messageSelfAndDeferRetirement(isNotNull(), captor.capture()); PassiveReplicationMessage.ChainReplicationMessage replicatedMessage = captor.getValue(); assertThat(replicatedMessage.concurrencyKey(), is(((ConcurrentEntityMessage) getAndAppend).concurrencyKey())); }
@Test public void testCallbackWithFunctionInParameterList() { ICallback callback = mock(ICallback.class); v8.registerJavaMethod(callback, "voidMethodWithObjectParameter", "foo", new Class<?>[] { V8Object.class }); v8.executeVoidScript("var bar = function() {}; foo(bar);"); verify(callback).voidMethodWithObjectParameter((V8Object) isNotNull()); }
@Test public void testCallbackWithExplicitFunctionInParameterList() { ICallback callback = mock(ICallback.class); v8.registerJavaMethod(callback, "voidMethodWithFunctionParameter", "foo", new Class<?>[] { V8Function.class }); v8.executeVoidScript("var bar = function() {}; foo(bar);"); verify(callback).voidMethodWithFunctionParameter((V8Function) isNotNull()); }
@Test public void nodekeyOptionMustBeUsed() throws Exception { final File file = new File("./specific/key"); parseCommand("--node-private-key-file", file.getPath()); verify(mockControllerBuilder).homePath(isNotNull()); verify(mockControllerBuilder).syncWithOttoman(eq(false)); verify(mockControllerBuilder).nodePrivateKeyFile(fileArgumentCaptor.capture()); verify(mockControllerBuilder).build(); assertThat(fileArgumentCaptor.getValue()).isEqualTo(file); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); }