/** function to create client cache * */ public static void createClientCache1(String host, Integer port1) throws Exception { PORT1 = port1.intValue(); Properties props = new Properties(); props.setProperty("mcast-port", "0"); props.setProperty("locators", ""); new PutAllDUnitTest("temp").createCache(props); props.setProperty("retryAttempts", "2"); props.setProperty("endpoints", "ep1=" + host + ":" + PORT1); props.setProperty("redundancyLevel", "-1"); props.setProperty("establishCallbackConnection", "true"); props.setProperty("LBPolicy", "Sticky"); props.setProperty("readTimeout", "2000"); props.setProperty("socketBufferSize", "1000"); props.setProperty("retryInterval", "250"); props.setProperty("connectionsPerServer", "2"); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); PoolImpl p = (PoolImpl) ClientServerTestCase.configureConnectionPool( factory, host, PORT1, -1, true, -1, 2, null); CacheListener clientListener = new HAEventIdPropagationListenerForClient1(); factory.setCacheListener(clientListener); RegionAttributes attrs = factory.create(); cache.createRegion(REGION_NAME, attrs); Region region = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(region); region.registerInterest("ALL_KEYS", InterestResultPolicy.NONE); pool = p; }
@Test public void testFailedIndexUpdateOnCommitForPut() throws Exception { Person.THROW_ON_INDEX = true; AttributesFactory af = new AttributesFactory(); af.setDataPolicy(DataPolicy.REPLICATE); SimpleListener sl = new SimpleListener(); af.setCacheListener(sl); Region region = cache.createRegion("sample", af.create()); qs.createIndex("foo", IndexType.FUNCTIONAL, "index", "/sample"); Context ctx = cache.getJNDIContext(); Integer x = new Integer(0); region.getCache().getCacheTransactionManager().begin(); region.create(x, new Person("xyz", 45)); try { region.getCache().getCacheTransactionManager().commit(); fail("commit should have thrown an exception because the index maintenance threw"); } catch (com.gemstone.gemfire.cache.query.IndexMaintenanceException ie) { // this is the desired case } Person p = (Person) region.get(x); assertEquals("object shouldn't have made it into region", null, p); assertEquals(0, sl.creates); assertEquals(0, sl.updates); }
public static void createClientCache(String host, Integer port1, Integer port2) throws Exception { PORT1 = port1.intValue(); PORT2 = port2.intValue(); Properties props = new Properties(); props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); props.setProperty(DistributionConfig.LOCATORS_NAME, ""); new DestroyEntryPropagationDUnitTest("temp").createCache(props); CacheServerTestUtil.disableShufflingOfEndpoints(); Pool p; try { p = PoolManager.createFactory() .addServer(host, PORT1) .addServer(host, PORT2) .setSubscriptionEnabled(true) .setSubscriptionRedundancy(-1) .setReadTimeout(2000) .setSocketBufferSize(1000) .setMinConnections(4) // .setRetryAttempts(2) // .setRetryInterval(250) .create("EntryPropagationDUnitTestPool"); } finally { CacheServerTestUtil.enableShufflingOfEndpoints(); } AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); factory.setPoolName(p.getName()); factory.setCacheListener(new CertifiableTestCacheListener(getLogWriter())); RegionAttributes attrs = factory.create(); cache.createRegion(REGION_NAME, attrs); }
public static Integer createServerCache() throws Exception { new DestroyEntryPropagationDUnitTest("temp").createCache(new Properties()); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); factory.setDataPolicy(DataPolicy.REPLICATE); factory.setCacheListener(new CertifiableTestCacheListener(getLogWriter())); RegionAttributes attrs = factory.create(); cache.createRegion(REGION_NAME, attrs); BridgeServer server = cache.addBridgeServer(); int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); server.setPort(port); server.setNotifyBySubscription(true); server.start(); return new Integer(server.getPort()); }
/** create the server * */ public static Integer createServerCache() throws Exception { new PutAllDUnitTest("temp").createCache(new Properties()); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); factory.setDataPolicy(DataPolicy.REPLICATE); CacheListener clientListener = new HAEventIdPropagationListenerForClient1(); factory.setCacheListener(clientListener); RegionAttributes attrs = factory.create(); cache.createRegion(REGION_NAME, attrs); server = (CacheServerImpl) cache.addCacheServer(); assertNotNull(server); int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); server.setPort(port); server.setNotifyBySubscription(true); server.start(); return new Integer(server.getPort()); }
/** * Creates the server cache, and configure wan * * @param site - used to configure gateway endpoint * @param name - used to generate name * @param ePort1 - GatewayHub port * @param ePort2 - other GatewayHub port * @throws Exception - thrown if any problem occurs in setting up the server */ public static Object createServerCache( String myHubId, String hubImSendingTo, Integer listenOnPort, Integer sendToPort, String host, int mcast_port, boolean enableStorage, boolean enableGateway) throws Exception { Properties props = new Properties(); props.setProperty(DistributionConfig.MCAST_PORT_NAME, mcast_port + ""); props.setProperty(DistributionConfig.LOCATORS_NAME, ""); cache = impl.createCache(props); AttributesFactory factory = impl.getServerCacheAttributesFactory(enableStorage); factory.setEnableGateway(true); factory.setCloningEnabled(false); factory.setCacheListener( new CacheListener() { public void afterCreate(EntryEvent event) { // TODO Auto-generated method stub } public void afterDestroy(EntryEvent event) { // TODO Auto-generated method stub } public void afterInvalidate(EntryEvent event) { // TODO Auto-generated method stub } public void afterRegionClear(RegionEvent event) { // TODO Auto-generated method stub } public void afterRegionCreate(RegionEvent event) { // TODO Auto-generated method stub } public void afterRegionDestroy(RegionEvent event) { // TODO Auto-generated method stub } public void afterRegionInvalidate(RegionEvent event) { // TODO Auto-generated method stub } public void afterRegionLive(RegionEvent event) { // TODO Auto-generated method stub } public void afterUpdate(EntryEvent event) { // TODO Auto-generated method stub } public void close() { // TODO Auto-generated method stub } }); RegionAttributes attrs = factory.create(); cache.createRegion(REGION_NAME, attrs); if (enableGateway) { GatewayHub hub1 = cache.addGatewayHub(myHubId, listenOnPort.intValue()); Gateway gateway1 = hub1.addGateway(hubImSendingTo); gateway1.addEndpoint("dont matter", host, sendToPort.intValue()); GatewayQueueAttributes queueAttributes = gateway1.getQueueAttributes(); queueAttributes.setMaximumQueueMemory(1); queueAttributes.setBatchSize(1); setDiskStoreForGateway(cache, gateway1.getId(), queueAttributes); hub1.start(); gateway1.start(); } return new Integer(0); }