/** * Determines whether the specified Cache has any CacheServers. * * @param cache the Cache to check for existing CacheServers. * @return a boolean value indicating if any CacheServers were added to the Cache. */ protected boolean isServing(final Cache cache) { return !cache.getCacheServers().isEmpty(); }
/** * Determines whether a default server (a cache server) should be created on startup as determined * by the absence of specifying the --disable-default-server command-line option (switch). In * addition, a default cache server is started only if no cache servers have been added to the * Cache by way of cache.xml. * * @param cache the reference to the Cache to check for any existing cache servers. * @return a boolean indicating whether a default server should be added to the Cache. * @see #isDisableDefaultServer() */ protected boolean isDefaultServerEnabled(final Cache cache) { return cache.getCacheServers().isEmpty() && !isDisableDefaultServer(); }
/** * Returns single CacheServer for the specified Cache instance */ public static CacheServer getCacheServer(final Cache cache) { List<CacheServer> cacheServers = cache.getCacheServers(); CacheServer cacheServer = cacheServers.get(0); return cacheServer; }
/** * Stops the cache server that serves up the given cache. * * @since GemFire 4.0 */ public void stopBridgeServers(Cache cache) { CacheServer bridge = null; for (Iterator bsI = cache.getCacheServers().iterator(); bsI.hasNext();) { bridge = (CacheServer) bsI.next(); bridge.stop(); assertFalse(bridge.isRunning()); } }
public static Integer createCacheServerFromXml(URL url) { CacheFactory ccf = new CacheFactory(); try { File cacheXmlFile = new File(url.toURI().getPath()); ccf.set(CACHE_XML_FILE, cacheXmlFile.toURI().getPath()); ccf.set(MCAST_PORT, "0"); ccf.set(LOCATORS, "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]"); } catch (URISyntaxException e) { throw new ExceptionInInitializerError(e); } cache = ccf.create(); return new Integer(cache.getCacheServers().get(0).getPort()); }
public static Integer createCacheServerFromXmlN(URL url) { CacheFactory ccf = new CacheFactory(); try { File cacheXmlFile = new File(url.toURI().getPath()); ccf.set(CACHE_XML_FILE, cacheXmlFile.toURI().getPath()); ccf.set(MCAST_PORT, "0"); ccf.set(LOCATORS, "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]"); ccf.set(LOG_FILE, "abs_server_system.log"); ccf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel()); } catch (URISyntaxException e) { throw new ExceptionInInitializerError(e); } cache = ccf.create(); return new Integer(cache.getCacheServers().get(0).getPort()); }
private static void verifyCacheClientProxyOnServer() { Cache cache = new ClientServerMiscDUnitTestBase().getCache(); assertEquals("More than one BridgeServer", 1, cache.getCacheServers().size()); CacheServerImpl bs = (CacheServerImpl) cache.getCacheServers().iterator().next(); assertNotNull(bs); assertNotNull(bs.getAcceptor()); final CacheClientNotifier ccn = bs.getAcceptor().getCacheClientNotifier(); assertNotNull(ccn); await() .until(() -> ccn.getClientProxies().size() == 1); }
@Test(timeout = 60_000) public void returnsImmediatelyIfCacheHasServers() { serverLauncher.running.set(true); List<CacheServer> servers = singletonList(mock(CacheServer.class)); when(cache.getCacheServers()).thenReturn(servers); when(system.isConnected()).thenReturn(true); when(cache.isReconnecting()).thenReturn(false); serverLauncher.waitOnServer(); } }
@Test(timeout = 60_000) public void returnsWhenLauncherIsRunningAndCacheIsNotReconnecting() { serverLauncher.running.set(true); when(cache.getCacheServers()).thenReturn(emptyList()); when(system.isConnected()).thenReturn(false); when(cache.isReconnecting()) .thenReturn(true, true, true) // Reconnecting for a while... .thenReturn(false); // ... then not serverLauncher.waitOnServer(); // Four times: true, true, true, false verify(cache, times(4)).isReconnecting(); }
private static void verifyNoCacheClientProxyOnServer() { try { Cache cache = new ClientServerMiscDUnitTestBase().getCache(); assertEquals("More than one BridgeServer", 1, cache.getCacheServers().size()); CacheServerImpl cacheServer = (CacheServerImpl) cache.getCacheServers().iterator().next(); assertNotNull(cacheServer); assertNotNull(cacheServer.getAcceptor()); final CacheClientNotifier ccn = cacheServer.getAcceptor().getCacheClientNotifier(); assertNotNull(ccn); await() .until(() -> ccn.getClientProxies().size() == 0); } catch (Exception ex) { System.out.println("The size of the client proxies != 0"); OSProcess.printStacks(0); throw ex; } }
@Test(timeout = 60_000) public void returnsWhenLauncherIsRunningAndSystemIsNotConnected() { serverLauncher.running.set(true); when(cache.getCacheServers()).thenReturn(emptyList()); when(cache.isReconnecting()).thenReturn(false); when(system.isConnected()) .thenReturn(true, true, true) // Connected for a while... .thenReturn(false); // ... then not serverLauncher.waitOnServer(); // Four times: false, false, false, true verify(system, times(4)).isConnected(); }
@Test public void isDefaultServerEnabledReturnsFalseWhenCacheServersExist() { Cache cache = mock(Cache.class, "Cache"); CacheServer cacheServer = mock(CacheServer.class, "CacheServer"); when(cache.getCacheServers()).thenReturn(Collections.singletonList(cacheServer)); ServerLauncher launcher = new Builder().build(); assertThat(launcher.isDefaultServerEnabled(cache)).isFalse(); }
@Test public void isServingReturnsTrueWhenCacheHasOneCacheServer() { Cache cache = mock(Cache.class); CacheServer cacheServer = mock(CacheServer.class); when(cache.getCacheServers()).thenReturn(Collections.singletonList(cacheServer)); ServerLauncher launcher = new Builder().build(); assertThat(launcher.isServing(cache)).isTrue(); }
@Test public void isServingReturnsFalseWhenCacheHasZeroCacheServers() { Cache cache = mock(Cache.class); when(cache.getCacheServers()).thenReturn(Collections.emptyList()); ServerLauncher launcher = new Builder().build(); assertThat(launcher.isServing(cache)).isFalse(); }
@Test public void isDefaultServerEnabledReturnsFalseWhenDefaultServerDisabledIsTrueAndCacheServersExist() { Cache cache = mock(Cache.class, "Cache"); CacheServer cacheServer = mock(CacheServer.class, "CacheServer"); when(cache.getCacheServers()).thenReturn(Collections.singletonList(cacheServer)); ServerLauncher launcher = new Builder().setDisableDefaultServer(true).build(); assertThat(launcher.isDefaultServerEnabled(cache)).isFalse(); }
@Test public void isDefaultServerEnabledReturnsFalseWhenDefaultServerDisabledIsTrueAndNoCacheServersExist() { Cache cache = mock(Cache.class, "Cache"); when(cache.getCacheServers()).thenReturn(Collections.emptyList()); ServerLauncher launcher = new Builder().setDisableDefaultServer(true).build(); assertThat(launcher.isDefaultServerEnabled(cache)).isFalse(); }
@Test public void reconnectedCacheIsClosed() { Cache cache = mock(Cache.class, "Cache"); Cache reconnectedCache = mock(Cache.class, "ReconnectedCache"); when(cache.isReconnecting()).thenReturn(false).thenReturn(false).thenReturn(true); when(cache.getCacheServers()).thenReturn(Collections.emptyList()); when(cache.getReconnectedCache()).thenReturn(reconnectedCache); new Builder().setCache(cache).build().waitOnServer(); verify(cache, atLeast(3)).isReconnecting(); verify(cache).getReconnectedCache(); verify(reconnectedCache).close(); }
@Test public void serverUsesFilteredCache() { serverVM.invoke(() -> { Cache serverCache = (Cache) cache; serverCache.createRegionFactory(RegionShortcut.REPLICATE).create("region"); }); clientVM.invoke(() -> { ClientCache clientCache = (ClientCache) cache; Region<String, String> region = clientCache.<String, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY) .create("region"); region.put("Object1", "Value1"); }); serverVM.invoke(() -> { Cache serverCache = (Cache) cache; CacheServer server = serverCache.getCacheServers().stream().findFirst().get(); CacheServerImpl impl = (CacheServerImpl) server; assertThat(impl.getAcceptor().getCachedRegionHelper().getCache()) .isInstanceOf(InternalCacheForClientAccess.class); }); }
@Test public void startCacheServerDoesNothingWhenDefaultServerDisabled() throws IOException { Cache cache = mock(Cache.class, "Cache"); CacheServer cacheServer = mock(CacheServer.class, "CacheServer"); when(cache.getCacheServers()).thenReturn(Collections.emptyList()); when(cache.addCacheServer()).thenReturn(cacheServer); ServerLauncher launcher = new Builder().setDisableDefaultServer(true).build(); launcher.startCacheServer(cache); verify(cacheServer, times(0)).setBindAddress(anyString()); verify(cacheServer, times(0)).setPort(anyInt()); verify(cacheServer, times(0)).setMaxThreads(anyInt()); verify(cacheServer, times(0)).setMaxConnections(anyInt()); verify(cacheServer, times(0)).setMaximumMessageCount(anyInt()); verify(cacheServer, times(0)).setMessageTimeToLive(anyInt()); verify(cacheServer, times(0)).setSocketBufferSize(anyInt()); verify(cacheServer, times(0)).setHostnameForClients(anyString()); verify(cacheServer, times(0)).start(); }
@Test public void startCacheServerStartsCacheServerWithBuilderValues() throws IOException { Cache cache = mock(Cache.class, "Cache"); CacheServer cacheServer = mock(CacheServer.class, "CacheServer"); when(cache.getCacheServers()).thenReturn(Collections.emptyList()); when(cache.addCacheServer()).thenReturn(cacheServer); ServerLauncher launcher = new Builder().setServerBindAddress(null).setServerPort(11235) .setMaxThreads(10).setMaxConnections(100).setMaxMessageCount(5).setMessageTimeToLive(10000) .setSocketBufferSize(2048).setHostNameForClients("hostName4Clients").build(); launcher.startCacheServer(cache); verify(cacheServer, times(1)).setBindAddress(null); verify(cacheServer, times(1)).setPort(eq(11235)); verify(cacheServer, times(1)).setMaxThreads(10); verify(cacheServer, times(1)).setMaxConnections(100); verify(cacheServer, times(1)).setMaximumMessageCount(5); verify(cacheServer, times(1)).setMessageTimeToLive(10000); verify(cacheServer, times(1)).setSocketBufferSize(2048); verify(cacheServer, times(1)).setHostnameForClients("hostName4Clients"); verify(cacheServer, times(1)).start(); }