protected int addCacheServer(final String[] groups) throws IOException { Cache cache = (Cache) remoteObjects.get(CACHE_KEY); CacheServer server = cache.addCacheServer(); server.setPort(0); server.setGroups(groups); server.start(); return server.getPort(); }
public static void createCacheServer(String regionName, Boolean notifyBySubscription, Integer serverPort) throws Exception { Properties props = new Properties(); props.setProperty(MCAST_PORT, "0"); props.setProperty(LOCATORS, "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]"); new CacheServerTestUtil().createCache(props); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); factory.setEnableBridgeConflation(true); factory.setDataPolicy(DataPolicy.REPLICATE); RegionAttributes attrs = factory.create(); cache.createRegion(regionName, attrs); CacheServer server = cache.addCacheServer(); server.setPort(serverPort.intValue()); server.setNotifyBySubscription(notifyBySubscription.booleanValue()); server.start(); }
/** * Starts a cache server on the given port * * @since GemFire 4.0 */ public int startBridgeServer(int port) throws IOException { Cache cache = getCache(); CacheServer bridge = cache.addCacheServer(); bridge.setPort(port); bridge.setMaxThreads(getMaxThreads()); bridge.start(); return bridge.getPort(); }
public static Integer createCacheServer(String regionName1, String regionName2, Boolean notifyBySubscription) throws Exception { new CacheServerTestUtil().createCache(new Properties()); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); factory.setEnableBridgeConflation(true); factory.setDataPolicy(DataPolicy.REPLICATE); RegionAttributes attrs = factory.create(); if (!regionName1.equals("")) { cache.createRegion(regionName1, attrs); } if (!regionName2.equals("")) { cache.createRegion(regionName2, attrs); } CacheServer server1 = cache.addCacheServer(); int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); server1.setPort(port); server1.setNotifyBySubscription(notifyBySubscription.booleanValue()); server1.start(); return new Integer(server1.getPort()); }
@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 startCacheServerDoesNothingWhenCacheServerAlreadyExists() throws IOException { Cache cache = mock(Cache.class, "Cache"); CacheServer cacheServer1 = mock(CacheServer.class, "CacheServer1"); CacheServer cacheServer2 = mock(CacheServer.class, "CacheServer2"); when(cache.getCacheServers()).thenReturn(Collections.singletonList(cacheServer1)); when(cache.addCacheServer()).thenReturn(cacheServer1); ServerLauncher launcher = new Builder().build(); launcher.startCacheServer(cache); verify(cacheServer2, times(0)).setBindAddress(anyString()); verify(cacheServer2, times(0)).setPort(anyInt()); verify(cacheServer2, times(0)).setMaxThreads(anyInt()); verify(cacheServer2, times(0)).setMaxConnections(anyInt()); verify(cacheServer2, times(0)).setMaximumMessageCount(anyInt()); verify(cacheServer2, times(0)).setMessageTimeToLive(anyInt()); verify(cacheServer2, times(0)).setSocketBufferSize(anyInt()); verify(cacheServer2, times(0)).setHostnameForClients(anyString()); verify(cacheServer2, 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(); }
protected int startBridgeServer(final String[] groups, final String locators, final String[] regions, final ServerLoadProbe probe, final boolean useGroupsProperty) throws IOException { CacheFactory cacheFactory = new CacheFactory().set(MCAST_PORT, "0").set(LOCATORS, locators); if (useGroupsProperty && groups != null) { cacheFactory.set(GROUPS, StringUtils.join(groups, ",")); } Cache cache = cacheFactory.create(); for (String regionName : regions) { cache.createRegionFactory(RegionShortcut.REPLICATE).setEnableSubscriptionConflation(true) .create(regionName); } CacheServer server = cache.addCacheServer(); server.setPort(0); if (!useGroupsProperty) { server.setGroups(groups); } server.setLoadProbe(probe); server.start(); remoteObjects.put(CACHE_KEY, cache); return server.getPort(); }
CacheServerImpl impl = (CacheServerImpl) cache.addCacheServer(); impl.configureFrom(declaredCacheServer);
protected int startBridgeServerWithEmbeddedLocator(final String[] groups, final String locators, final String[] regions, final ServerLoadProbe probe) throws IOException { Cache cache = new CacheFactory().set(MCAST_PORT, "0").set(LOCATORS, locators) .set(START_LOCATOR, locators).create(); for (String regionName : regions) { cache.createRegionFactory(RegionShortcut.REPLICATE).setEnableSubscriptionConflation(true) .create(regionName); } CacheServer server = cache.addCacheServer(); server.setGroups(groups); server.setLoadProbe(probe); server.setPort(0); server.start(); remoteObjects.put(CACHE_KEY, cache); return server.getPort(); }
int port = serverPort <= 0 ? 0 : serverPort; CacheServer server1 = cache.addCacheServer();
@Before public void setup() { serverVM = VM.getVM(0); clientVM = VM.getVM(1); final int locatorPort = DistributedTestUtils.getDUnitLocatorPort(); // create a server cache and a client cache serverVM.invoke(() -> { String locatorSpec = "localhost[" + locatorPort + "]"; CacheFactory config = new CacheFactory(); config.set( ConfigurationProperties.LOCATORS, locatorSpec); config.set( ConfigurationProperties.NAME, "server1"); Cache serverCache = config.create(); cache = serverCache; CacheServer cacheServer = serverCache.addCacheServer(); cacheServer.start(); }); clientVM.invoke(() -> { ClientCacheFactory config = new ClientCacheFactory(); config.addPoolLocator("localhost", locatorPort); config.setPoolSubscriptionEnabled(true); cache = config.create(); }); }
getServerBindAddress() == null ? null : getServerBindAddress().getHostAddress(); final Integer serverPort = getServerPort(); final CacheServer cacheServer = cache.addCacheServer(); cacheServer.setBindAddress(serverBindAddress); cacheServer.setPort(serverPort);
assertNotNull(pr); CacheServer server = cache.addCacheServer(); int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); r1.getCache().getDistributedSystem().getLogWriter().info("Starting server on port " + port);
public static void main(String[] args) throws Exception { Properties props = new Properties(); props.setProperty("name", "CacheServer at " + new Date()); props.setProperty("log-level", "info"); logger.info("Connecting to the distributed system and creating the cache."); Cache cache = new CacheFactory(props).create(); // Create region. Region<?, ?> region = cache.createRegionFactory(RegionShortcut.REPLICATE) .setScope(Scope.DISTRIBUTED_ACK) .create("test"); logger.info("Test region, " + region.getFullPath() + ", created in cache."); // Start Cache Server. CacheServer server = cache.addCacheServer(); server.setPort(40404); logger.info("Starting server"); server.start(); ForkUtil.createControlFile(CacheServerProcess.class.getName()); logger.info("Waiting for shutdown"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); bufferedReader.readLine(); }
/** * Adds a {@link CacheServer} to the given {@link Cache} for server {@link ClientCache cache clients}. * * @param cache {@link Cache} used to add a {@link CacheServer}. * @return the newly added {@link CacheServer}. * @see org.apache.geode.cache.Cache#addCacheServer() * @see org.apache.geode.cache.server.CacheServer */ protected CacheServer addCacheServer(Cache cache) { return cache.addCacheServer(); }
/** * Adds a {@link CacheServer} to the given {@link Cache} for server {@link ClientCache cache clients}. * * @param cache {@link Cache} used to add a {@link CacheServer}. * @return the newly added {@link CacheServer}. * @see org.apache.geode.cache.Cache#addCacheServer() * @see org.apache.geode.cache.server.CacheServer */ protected CacheServer addCacheServer(Cache cache) { return cache.addCacheServer(); }
when(mockCache.addCacheServer()).thenAnswer(invocation -> {