@Test public void defaultCacheServerIsNotCreatedWhenDisableDefaultCacheServerIsTrue() { CacheCreation cacheCreation = new CacheCreation(); CacheServerImpl mockServer = mock(CacheServerImpl.class); when(this.cache.addCacheServer()).thenReturn(mockServer); List<CacheServer> cacheServers = new ArrayList<>(); when(this.cache.getCacheServers()).thenReturn(cacheServers); cacheCreation.startCacheServers(cacheCreation.getCacheServers(), this.cache, ServerLauncherParameters.INSTANCE.withDisableDefaultServer(false)); verify(this.cache, never()).addCacheServer(); }
@Test public void defaultCacheServerIsNotCreatedWithDefaultPortWhenNoDeclarativeServerIsConfigured() { CacheCreation cacheCreation = new CacheCreation(); CacheServerImpl mockServer = mock(CacheServerImpl.class); when(this.cache.addCacheServer()).thenReturn(mockServer); List<CacheServer> cacheServers = new ArrayList<>(); when(this.cache.getCacheServers()).thenReturn(cacheServers); cacheCreation.startCacheServers(cacheCreation.getCacheServers(), this.cache, ServerLauncherParameters.INSTANCE.withDisableDefaultServer(false)); verify(this.cache, never()).addCacheServer(); }
@Test public void defaultCacheServerIsCreatedWithConfiguredPortWhenNoDeclarativeServerIsConfigured() { CacheCreation cacheCreation = new CacheCreation(); CacheServerImpl mockServer = mock(CacheServerImpl.class); when(this.cache.addCacheServer()).thenReturn(mockServer); List<CacheServer> cacheServers = new ArrayList<>(); when(this.cache.getCacheServers()).thenReturn(cacheServers); Boolean disableDefaultCacheServer = false; Integer configuredServerPort = 9999; cacheCreation.startCacheServers(cacheCreation.getCacheServers(), this.cache, ServerLauncherParameters.INSTANCE.withPort(configuredServerPort) .withDisableDefaultServer(disableDefaultCacheServer)); verify(this.cache, times(1)).addCacheServer(); verify(mockServer).setPort(9999); }
@Test public void cacheServerCreationIsSkippedWhenAServerExistsForAGivenPort() { CacheCreation cacheCreation = new CacheCreation(); CacheServerCreation br1 = new CacheServerCreation(cacheCreation, false); br1.setPort(40406); cacheCreation.getCacheServers().add(br1); CacheServerImpl mockServer = mock(CacheServerImpl.class); when(this.cache.addCacheServer()).thenReturn(mockServer); when(mockServer.getPort()).thenReturn(40406); List<CacheServer> cacheServers = new ArrayList<>(); cacheServers.add(mockServer); when(this.cache.getCacheServers()).thenReturn(cacheServers); cacheCreation.startCacheServers(cacheCreation.getCacheServers(), this.cache, ServerLauncherParameters.INSTANCE.withDisableDefaultServer(false)); verify(this.cache, never()).addCacheServer(); }
@Test public void declarativeCacheServerIsCreatedWithConfiguredServerPort() { CacheCreation cacheCreation = new CacheCreation(); CacheServerCreation br1 = new CacheServerCreation(cacheCreation, false); br1.setPort(8888); cacheCreation.getCacheServers().add(br1); CacheServerImpl mockServer = mock(CacheServerImpl.class); when(this.cache.addCacheServer()).thenReturn(mockServer); Integer configuredServerPort = 9999; Boolean disableDefaultCacheServer = false; cacheCreation.startCacheServers(cacheCreation.getCacheServers(), this.cache, ServerLauncherParameters.INSTANCE.withPort(configuredServerPort) .withDisableDefaultServer(disableDefaultCacheServer)); verify(this.cache, times(1)).addCacheServer(); verify(mockServer).setPort(configuredServerPort); }
@Test public void userCanCreateMultipleCacheServersDeclaratively() { CacheCreation cacheCreation = new CacheCreation(); CacheServerCreation br1 = new CacheServerCreation(cacheCreation, false); br1.setPort(40406); CacheServerCreation br2 = new CacheServerCreation(cacheCreation, false); br1.setPort(40407); cacheCreation.getCacheServers().add(br1); cacheCreation.getCacheServers().add(br2); CacheServerImpl mockServer = mock(CacheServerImpl.class); when(this.cache.addCacheServer()).thenReturn(mockServer); cacheCreation.startCacheServers(cacheCreation.getCacheServers(), this.cache, ServerLauncherParameters.INSTANCE.withDisableDefaultServer(false)); verify(this.cache, times(2)).addCacheServer(); verify(mockServer).configureFrom(br1); verify(mockServer).configureFrom(br2); }
.withHostnameForClients(hostnameForClients) .withDisableDefaultServer(disableDefaultServer); cacheCreation.startCacheServers(cacheCreation.getCacheServers(), this.cache, ServerLauncherParameters.INSTANCE);
@Test(expected = RuntimeException.class) public void shouldThrowExceptionWhenUserTriesToDeclareMultipleCacheServersWithPort() { CacheCreation cacheCreation = new CacheCreation(); cacheCreation.getCacheServers().add(new CacheServerCreation(cacheCreation, false)); cacheCreation.getCacheServers().add(new CacheServerCreation(cacheCreation, false)); Integer configuredServerPort = 50505; String configuredServerBindAddress = "localhost[50505]"; Boolean disableDefaultCacheServer = false; cacheCreation.startCacheServers(cacheCreation.getCacheServers(), this.cache, ServerLauncherParameters.INSTANCE.withPort(configuredServerPort) .withBindAddress(configuredServerBindAddress) .withDisableDefaultServer(disableDefaultCacheServer)); }
startCacheServers(getCacheServers(), cache, ServerLauncherParameters.INSTANCE);