@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);
  }
 /** Helper Methods */
 private void createLocalRegion() throws ParseException {
   Cache cache = CacheUtils.getCache();
   AttributesFactory attributesFactory = new AttributesFactory();
   attributesFactory.setDataPolicy(DataPolicy.NORMAL);
   RegionAttributes regionAttributes = attributesFactory.create();
   Region region = cache.createRegion(regionName, regionAttributes);
 }
 private void createRegion(boolean accessor, int redundantCopies, InterestPolicy interestPolicy) {
   AttributesFactory af = new AttributesFactory();
   af.setScope(Scope.DISTRIBUTED_ACK);
   af.setDataPolicy(DataPolicy.REPLICATE);
   af.setCloningEnabled(true);
   getCache().createRegion(D_REFERENCE, af.create());
   af = new AttributesFactory();
   af.setCloningEnabled(true);
   if (interestPolicy != null) {
     af.setSubscriptionAttributes(new SubscriptionAttributes(interestPolicy));
   }
   af.setPartitionAttributes(
       new PartitionAttributesFactory<CustId, Customer>()
           .setTotalNumBuckets(4)
           .setLocalMaxMemory(accessor ? 0 : 1)
           .setPartitionResolver(new CustomerIDPartitionResolver("resolver1"))
           .setRedundantCopies(redundantCopies)
           .create());
   getCache().createRegion(CUSTOMER, af.create());
   af.setPartitionAttributes(
       new PartitionAttributesFactory<OrderId, Order>()
           .setTotalNumBuckets(4)
           .setLocalMaxMemory(accessor ? 0 : 1)
           .setPartitionResolver(new CustomerIDPartitionResolver("resolver2"))
           .setRedundantCopies(redundantCopies)
           .setColocatedWith(CUSTOMER)
           .create());
   getCache().createRegion(ORDER, af.create());
 }
 public void DISABLED_testTxWithCloning() {
   AttributesFactory af = new AttributesFactory();
   af.setDataPolicy(DataPolicy.REPLICATE);
   af.setScope(Scope.DISTRIBUTED_ACK);
   af.setCloningEnabled(true);
   basicTest(af.create());
 }
  @Override
  @SuppressWarnings({"rawtypes", "unchecked"})
  public Family createMappedForm(PersistentEntity entity) {
    ClassPropertyFetcher cpf = ClassPropertyFetcher.forClass(entity.getJavaClass());
    final Closure value = cpf.getStaticPropertyValue(GormProperties.MAPPING, Closure.class);
    if (value == null) {
      return new Region();
    }

    final Region family = new Region();
    AttributesFactory factory =
        new AttributesFactory() {
          @SuppressWarnings("unused")
          public void setRegion(String name) {
            family.setRegion(name);
          }
        };
    factory.setDataPolicy(defaultDataPolicy);

    MappingConfigurationBuilder builder = new MappingConfigurationBuilder(factory, KeyValue.class);
    builder.evaluate(value);
    entityToPropertyMap.put(entity, builder.getProperties());
    final RegionAttributes regionAttributes = factory.create();
    family.setRegionAttributes(regionAttributes);
    family.setCacheListeners(regionAttributes.getCacheListeners());
    family.setDataPolicy(regionAttributes.getDataPolicy());
    family.setCacheLoader(regionAttributes.getCacheLoader());
    family.setCacheWriter(regionAttributes.getCacheWriter());

    builder = new MappingConfigurationBuilder(family, KeyValue.class);
    builder.evaluate(value);
    return family;
  }
  @Test
  public void testAllIndexesOnCommitForPut() throws Exception {
    // create region
    AttributesFactory af = new AttributesFactory();
    af.setDataPolicy(DataPolicy.REPLICATE);
    Region region = cache.createRegion("sample", af.create());

    // put data
    for (int i = 0; i < 10; i++) {
      region.put(i, new Portfolio(i));
    }

    String[] queries = {
      "select * from /sample where ID = 5",
      "select ID from /sample where ID < 5",
      "select ID from /sample where ID > 5",
      "select ID from /sample where ID != 5",
      "select status from /sample where status = 'active'",
      "select status from /sample where status > 'active'",
      "select status from /sample where status < 'active'",
      "select status from /sample where status != 'active'",
      "select pos.secId from /sample p, p.positions.values pos where pos.secId = 'IBM'",
      "select pos.secId from /sample p, p.positions.values pos where pos.secId < 'VMW'",
      "select pos.secId from /sample p, p.positions.values pos where pos.secId > 'IBM'",
      "select pos.secId from /sample p, p.positions.values pos where pos.secId != 'IBM'"
    };

    SelectResults[][] sr = new SelectResults[queries.length][2];

    // execute queries without indexes
    for (int i = 0; i < queries.length; i++) {
      sr[i][0] = (SelectResults) qs.newQuery(queries[i]).execute();
    }

    // create indexes
    qs.createKeyIndex("IDIndex", "ID", "/sample");
    qs.createIndex("statusIndex", "status", "/sample");
    qs.createIndex("secIdIndex", "pos.secId", "/sample p, p.positions.values pos");

    // begin transaction
    Context ctx = cache.getJNDIContext();
    UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
    utx.begin();

    // update data
    for (int i = 0; i < 10; i++) {
      region.put(i, new Portfolio(i));
    }

    // execute queries with indexes during transaction
    for (int i = 0; i < queries.length; i++) {
      sr[i][1] = (SelectResults) qs.newQuery(queries[i]).execute();
    }

    // complete transaction
    utx.commit();

    // verify results
    com.gemstone.gemfire.cache.query.CacheUtils.compareResultsOfWithAndWithoutIndex(sr);
  }
 private RegionAttributes createRegionAttributes(boolean isConcurrencyChecksEnabled) {
   AttributesFactory factory = new AttributesFactory();
   factory.setScope(Scope.DISTRIBUTED_ACK);
   factory.setDataPolicy(DataPolicy.REPLICATE);
   factory.setConcurrencyChecksEnabled(isConcurrencyChecksEnabled); //
   RegionAttributes ra = factory.create();
   return ra;
 }
 /**
  * create a client with 2 regions sharing a common writer
  *
  * @throws Exception
  */
 public static void createRegion() throws Exception {
   HARegionDUnitTest test = new HARegionDUnitTest(REGION_NAME);
   cache = test.createCache();
   AttributesFactory factory = new AttributesFactory();
   factory.setScope(Scope.DISTRIBUTED_ACK);
   factory.setDataPolicy(DataPolicy.REPLICATE);
   HARegion.getInstance(REGION_NAME, (GemFireCacheImpl) cache, null, factory.create());
 }
  protected AttributesFactory getServerCacheAttributesFactory(boolean enableStorage) {
    AttributesFactory factory = new AttributesFactory();
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    factory.setDataPolicy(DataPolicy.PARTITION);
    paf.setRedundantCopies(0).setTotalNumBuckets(1);
    if (!enableStorage) {
      paf.setLocalMaxMemory(0);
    }

    factory.setPartitionAttributes(paf.create());
    return factory;
  }
 protected RegionAttributes getDiskRegionAttributes() {
   AttributesFactory factory = new AttributesFactory(getRegionAttributes());
   File[] diskDirs = new File[1];
   diskDirs[0] = new File("diskRegionDirs/" + OSProcess.getId());
   diskDirs[0].mkdirs();
   factory.setDiskStoreName(
       getCache()
           .createDiskStoreFactory()
           .setDiskDirs(diskDirs)
           .setTimeInterval(1000)
           .setQueueSize(0)
           .create("TXRestrictionsDUnitTest")
           .getName());
   factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
   return factory.create();
 }
  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());
 }
 // @Test
 public void _testFailedIndexUpdateOnJTACommitForPut() throws Exception {
   Person.THROW_ON_INDEX = true;
   AttributesFactory af = new AttributesFactory();
   af.setDataPolicy(DataPolicy.REPLICATE);
   Region region = cache.createRegion("sample", af.create());
   qs.createIndex("foo", IndexType.FUNCTIONAL, "index", "/sample");
   Context ctx = cache.getJNDIContext();
   UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
   Integer x = new Integer(0);
   utx.begin();
   region.create(x, new Person("xyz", 45));
   try {
     utx.commit();
     fail("Commit should have thrown an exception because the index update threw");
   } catch (Exception e) {
     // this is desired
   }
 }
 public static void createCacheServer(
     String regionName, Boolean notifyBySubscription, Integer mcastPort, Integer serverPort)
     throws Exception {
   Properties props = new Properties();
   props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
   props.setProperty(
       DistributionConfig.LOCATORS_NAME,
       "localhost[" + DistributedTestCase.getDUnitLocatorPort() + "]");
   new CacheServerTestUtil("temp").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);
   BridgeServer server = cache.addBridgeServer();
   server.setPort(serverPort.intValue());
   server.setNotifyBySubscription(notifyBySubscription.booleanValue());
   server.start();
 }
  public void testExceptionThrown() {
    AttributesFactory af = new AttributesFactory();
    af.setDataPolicy(DataPolicy.REPLICATE);
    af.setScope(Scope.DISTRIBUTED_ACK);
    final RegionAttributes attr = af.create();
    Host host = Host.getHost(0);
    VM vm1 = host.getVM(0);
    VM vm2 = host.getVM(1);
    final String regionName = getUniqueName();

    SerializableCallable createRegion =
        new SerializableCallable() {
          public Object call() throws Exception {
            getCache().createRegion(regionName, attr);
            return null;
          }
        };

    vm1.invoke(createRegion);
    vm2.invoke(createRegion);
    final String key = "cust1";

    vm1.invoke(
        new SerializableCallable() {
          public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            Region r = getCache().getRegion(regionName);
            Customer cust = new Customer(1, "cust1");
            r.put(key, cust);
            mgr.begin();
            cust.setName("");
            try {
              r.put(key, cust);
              fail("exception not thrown");
            } catch (UnsupportedOperationInTransactionException expected) {
            }
            mgr.rollback();
            return null;
          }
        });
  }
 public static Integer createCacheServer(
     String regionName1, String regionName2, Boolean notifyBySubscription) throws Exception {
   new CacheServerTestUtil("temp").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);
   }
   BridgeServer server1 = cache.addBridgeServer();
   int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
   server1.setPort(port);
   server1.setNotifyBySubscription(notifyBySubscription.booleanValue());
   server1.start();
   return new Integer(server1.getPort());
 }
 @Test
 public void testIndexOnCommitForDestroy() throws Exception {
   AttributesFactory af = new AttributesFactory();
   af.setDataPolicy(DataPolicy.REPLICATE);
   Region region = cache.createRegion("sample", af.create());
   qs.createIndex("foo", IndexType.FUNCTIONAL, "age", "/sample");
   Context ctx = cache.getJNDIContext();
   UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
   Integer x = new Integer(0);
   utx.begin();
   region.create(x, new Person("xyz", 45));
   utx.commit();
   Query q = qs.newQuery("select * from /sample where age < 50");
   assertEquals(1, ((SelectResults) q.execute()).size());
   Person dsample = (Person) CopyHelper.copy(region.get(x));
   dsample.setAge(55);
   utx.begin();
   region.destroy(x);
   utx.commit();
   CacheUtils.log(((Person) region.get(x)));
   assertEquals(0, ((SelectResults) q.execute()).size());
 }
 public static Integer[] createCacheServerReturnPorts(
     String regionName, Boolean notifyBySubscription) throws Exception {
   Properties props = new Properties();
   //    int mcastPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
   props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
   props.setProperty(
       DistributionConfig.LOCATORS_NAME,
       "localhost[" + DistributedTestCase.getDUnitLocatorPort() + "]");
   new CacheServerTestUtil("temp").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);
   BridgeServer server1 = cache.addBridgeServer();
   int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
   server1.setPort(port);
   server1.setNotifyBySubscription(notifyBySubscription.booleanValue());
   server1.start();
   return new Integer[] {port, 0};
 }
Пример #19
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  protected void initializeRegion() {
    String regionName = DQueue.NAME_PREFIX + this.id;
    Region region = this.cache.getRegion(regionName);
    boolean createdRegion = false;

    // Create the dq region if necessary
    if (region == null) {
      GemFireCacheImpl gfci = (GemFireCacheImpl) this.cache;
      if (gfci.isClient()) {
        // can't use the createRegion method if this cache is a client-cache
        ClientRegionFactory factory = gfci.createClientRegionFactory(ClientRegionShortcut.PROXY);
        factory.setPoolName(this.dqAttributes.getPoolName());
        region = factory.create(regionName);
      } else {
        AttributesFactory factory = new AttributesFactory();
        factory.setDataPolicy(DataPolicy.EMPTY);
        factory.setScope(Scope.LOCAL);
        factory.setPoolName(this.dqAttributes.getPoolName());
        region = this.dqRegion = this.cache.createRegion(regionName, factory.create());
        createdRegion = true;
      }
    }

    this.dqRegion = region;

    if (this.cache.getLogger().fineEnabled()) {
      this.cache
          .getLogger()
          .fine(
              this
                  + ": "
                  + (createdRegion ? "Created" : "Retrieved")
                  + " DQueue region: "
                  + this.dqRegion.getFullPath());
    }
  }
  public static void main(String[] args) throws Exception {

    Properties props = new Properties();
    props.setProperty("name", "CqServer");
    props.setProperty("log-level", "warning");

    System.out.println("\nConnecting to the distributed system and creating the cache.");
    DistributedSystem ds = DistributedSystem.connect(props);
    Cache cache = CacheFactory.create(ds);

    // Create region.
    AttributesFactory factory = new AttributesFactory();
    factory.setDataPolicy(DataPolicy.REPLICATE);
    factory.setScope(Scope.DISTRIBUTED_ACK);
    Region testRegion = cache.createRegion("test-cq", factory.create());
    System.out.println("Test region, " + testRegion.getFullPath() + ", created in cache.");

    // Start Cache Server.
    CacheServer server = cache.addCacheServer();
    server.setPort(40404);
    server.setNotifyBySubscription(true);
    server.start();

    System.out.println("Waiting for signal");
    // wait for signal
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    bufferedReader.readLine();

    System.out.println("Received signal");

    testRegion.put("one", 1);
    testRegion.put("two", 2);
    testRegion.put("three", 3);

    System.out.println("Waiting for shutdown");
    bufferedReader.readLine();
  }
  /** check remote ops done in a normal vm are correctly distributed to PROXY regions */
  private void remoteOriginOps(DataPolicy dp, InterestPolicy ip) throws CacheException {
    initOtherId();
    AttributesFactory af = new AttributesFactory();
    af.setDataPolicy(dp);
    af.setSubscriptionAttributes(new SubscriptionAttributes(ip));
    af.setScope(Scope.DISTRIBUTED_ACK);
    CacheListener cl1 =
        new CacheListener() {
          public void afterUpdate(EntryEvent e) {
            clLastEvent = e;
            clInvokeCount++;
          }

          public void afterCreate(EntryEvent e) {
            clLastEvent = e;
            clInvokeCount++;
          }

          public void afterInvalidate(EntryEvent e) {
            clLastEvent = e;
            clInvokeCount++;
          }

          public void afterDestroy(EntryEvent e) {
            clLastEvent = e;
            clInvokeCount++;
          }

          public void afterRegionInvalidate(RegionEvent e) {
            clLastEvent = e;
            clInvokeCount++;
          }

          public void afterRegionDestroy(RegionEvent e) {
            clLastEvent = e;
            clInvokeCount++;
          }

          public void afterRegionClear(RegionEvent e) {
            clLastEvent = e;
            clInvokeCount++;
          }

          public void afterRegionCreate(RegionEvent e) {}

          public void afterRegionLive(RegionEvent e) {}

          public void close() {}
        };
    af.addCacheListener(cl1);
    Region r = createRootRegion("ProxyDUnitTest", af.create());
    this.clInvokeCount = 0;

    doCreateOtherVm();

    DMStats stats = getDMStats();
    long receivedMsgs = stats.getReceivedMessages();

    if (ip.isAll()) {
      getOtherVm()
          .invoke(
              new CacheSerializableRunnable("do put") {
                public void run2() throws CacheException {
                  Region r = getRootRegion("ProxyDUnitTest");
                  r.put("p", "v");
                }
              });
      assertEquals(1, this.clInvokeCount);
      assertEquals(Operation.CREATE, this.clLastEvent.getOperation());
      assertEquals(true, this.clLastEvent.isOriginRemote());
      assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
      assertEquals(null, ((EntryEvent) this.clLastEvent).getOldValue());
      assertEquals(false, ((EntryEvent) this.clLastEvent).isOldValueAvailable()); // failure
      assertEquals("v", ((EntryEvent) this.clLastEvent).getNewValue());
      assertEquals("p", ((EntryEvent) this.clLastEvent).getKey());
      this.clInvokeCount = 0;

      getOtherVm()
          .invoke(
              new CacheSerializableRunnable("do create") {
                public void run2() throws CacheException {
                  Region r = getRootRegion("ProxyDUnitTest");
                  r.create("c", "v");
                }
              });
      assertEquals(1, this.clInvokeCount);
      assertEquals(Operation.CREATE, this.clLastEvent.getOperation());
      assertEquals(true, this.clLastEvent.isOriginRemote());
      assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
      assertEquals(null, ((EntryEvent) this.clLastEvent).getOldValue());
      assertEquals(false, ((EntryEvent) this.clLastEvent).isOldValueAvailable());
      assertEquals("v", ((EntryEvent) this.clLastEvent).getNewValue());
      assertEquals("c", ((EntryEvent) this.clLastEvent).getKey());
      this.clInvokeCount = 0;

      getOtherVm()
          .invoke(
              new CacheSerializableRunnable("do update") {
                public void run2() throws CacheException {
                  Region r = getRootRegion("ProxyDUnitTest");
                  r.put("c", "v2");
                }
              });
      assertEquals(1, this.clInvokeCount);
      assertEquals(Operation.UPDATE, this.clLastEvent.getOperation());
      assertEquals(true, this.clLastEvent.isOriginRemote());
      assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
      assertEquals(null, ((EntryEvent) this.clLastEvent).getOldValue());
      assertEquals(false, ((EntryEvent) this.clLastEvent).isOldValueAvailable());
      assertEquals("v2", ((EntryEvent) this.clLastEvent).getNewValue());
      assertEquals("c", ((EntryEvent) this.clLastEvent).getKey());
      this.clInvokeCount = 0;

      getOtherVm()
          .invoke(
              new CacheSerializableRunnable("do invalidate") {
                public void run2() throws CacheException {
                  Region r = getRootRegion("ProxyDUnitTest");
                  r.invalidate("c");
                }
              });
      assertEquals(1, this.clInvokeCount);
      assertEquals(Operation.INVALIDATE, this.clLastEvent.getOperation());
      assertEquals(true, this.clLastEvent.isOriginRemote());
      assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
      assertEquals(null, ((EntryEvent) this.clLastEvent).getOldValue());
      assertEquals(false, ((EntryEvent) this.clLastEvent).isOldValueAvailable());
      assertEquals(null, ((EntryEvent) this.clLastEvent).getNewValue());
      assertEquals("c", ((EntryEvent) this.clLastEvent).getKey());
      this.clInvokeCount = 0;

      getOtherVm()
          .invoke(
              new CacheSerializableRunnable("do destroy") {
                public void run2() throws CacheException {
                  Region r = getRootRegion("ProxyDUnitTest");
                  r.destroy("c");
                }
              });
      assertEquals(1, this.clInvokeCount);
      assertEquals(Operation.DESTROY, this.clLastEvent.getOperation());
      assertEquals(true, this.clLastEvent.isOriginRemote());
      assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
      assertEquals(null, ((EntryEvent) this.clLastEvent).getOldValue());
      assertEquals(false, ((EntryEvent) this.clLastEvent).isOldValueAvailable());
      assertEquals(null, ((EntryEvent) this.clLastEvent).getNewValue());
      assertEquals("c", ((EntryEvent) this.clLastEvent).getKey());
      this.clInvokeCount = 0;

      getOtherVm()
          .invoke(
              new CacheSerializableRunnable("do putAll") {
                public void run2() throws CacheException {
                  Region r = getRootRegion("ProxyDUnitTest");
                  Map m = new HashMap();
                  m.put("putAllKey1", "putAllValue1");
                  m.put("putAllKey2", "putAllValue2");
                  r.putAll(m);
                }
              });
      assertEquals(2, this.clInvokeCount);
      // @todo darrel; check putAll events
      this.clInvokeCount = 0;

      getOtherVm()
          .invoke(
              new CacheSerializableRunnable("do netsearch") {
                public void run2() throws CacheException {
                  Region r = getRootRegion("ProxyDUnitTest");
                  assertEquals(null, r.get("loadkey")); // total miss
                }
              });
      assertEquals(0, this.clInvokeCount);

    } else {
      getOtherVm()
          .invoke(
              new CacheSerializableRunnable("do entry ops") {
                public void run2() throws CacheException {
                  Region r = getRootRegion("ProxyDUnitTest");
                  r.put("p", "v");
                  r.create("c", "v");
                  r.put("c", "v"); // update
                  r.invalidate("c");
                  r.destroy("c");
                  {
                    Map m = new HashMap();
                    m.put("putAllKey1", "putAllValue1");
                    m.put("putAllKey2", "putAllValue2");
                    r.putAll(m);
                  }
                  assertEquals(null, r.get("loadkey")); // total miss
                }
              });

      assertEquals(0, this.clInvokeCount);
      assertEquals(0, r.size());
      // check the stats to make sure none of the above sent up messages
      assertEquals(receivedMsgs, stats.getReceivedMessages());
    }

    {
      AttributesMutator am = r.getAttributesMutator();
      CacheLoader cl =
          new CacheLoader() {
            public Object load(LoaderHelper helper) throws CacheLoaderException {
              if (helper.getKey().equals("loadkey")) {
                return "loadvalue";
              } else if (helper.getKey().equals("loadexception")) {
                throw new CacheLoaderException("expected");
              } else {
                return null;
              }
            }

            public void close() {}
          };
      am.setCacheLoader(cl);
    }

    receivedMsgs = stats.getReceivedMessages();
    getOtherVm()
        .invoke(
            new CacheSerializableRunnable("check net loader") {
              public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                assertEquals("loadvalue", r.get("loadkey")); // net load
                assertEquals(null, r.get("foobar")); // total miss
                try {
                  r.get("loadexception");
                  fail("expected CacheLoaderException");
                } catch (CacheLoaderException expected) {
                }
              }
            });
    assertTrue(stats.getReceivedMessages() > receivedMsgs);
    if (ip.isAll()) {
      assertEquals(1, this.clInvokeCount);
      assertEquals(Operation.NET_LOAD_CREATE, this.clLastEvent.getOperation());
      assertEquals(true, this.clLastEvent.isOriginRemote());
      assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
      assertEquals(null, ((EntryEvent) this.clLastEvent).getOldValue());
      assertEquals(false, ((EntryEvent) this.clLastEvent).isOldValueAvailable());
      this.clInvokeCount = 0;
    } else {
      assertEquals(0, this.clInvokeCount);
    }

    {
      AttributesMutator am = r.getAttributesMutator();
      am.setCacheLoader(null);
      CacheWriter cw =
          new CacheWriterAdapter() {
            public void beforeCreate(EntryEvent event) throws CacheWriterException {
              throw new CacheWriterException("expected");
            }
          };
      am.setCacheWriter(cw);
    }
    receivedMsgs = stats.getReceivedMessages();
    getOtherVm()
        .invoke(
            new CacheSerializableRunnable("check net write") {
              public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                try {
                  r.put("putkey", "putvalue");
                  fail("expected CacheWriterException");
                } catch (CacheWriterException expected) {
                }
              }
            });
    assertTrue(stats.getReceivedMessages() > receivedMsgs);
    {
      AttributesMutator am = r.getAttributesMutator();
      am.setCacheWriter(null);
    }
    assertEquals(0, this.clInvokeCount);
    this.clLastEvent = null;
    getOtherVm()
        .invoke(
            new CacheSerializableRunnable("check region invalidate") {
              public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                r.invalidateRegion();
              }
            });
    assertEquals(1, this.clInvokeCount);
    assertEquals(Operation.REGION_INVALIDATE, this.clLastEvent.getOperation());
    assertEquals(true, this.clLastEvent.isOriginRemote());
    assertEquals(this.otherId, this.clLastEvent.getDistributedMember());

    this.clLastEvent = null;
    getOtherVm()
        .invoke(
            new CacheSerializableRunnable("check region clear") {
              public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                r.clear();
              }
            });
    assertEquals(2, this.clInvokeCount);
    assertEquals(Operation.REGION_CLEAR, this.clLastEvent.getOperation());
    assertEquals(true, this.clLastEvent.isOriginRemote());
    assertEquals(this.otherId, this.clLastEvent.getDistributedMember());

    this.clLastEvent = null;
    getOtherVm()
        .invoke(
            new CacheSerializableRunnable("check region destroy") {
              public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                r.destroyRegion();
              }
            });
    assertEquals(3, this.clInvokeCount);
    assertEquals(Operation.REGION_DESTROY, this.clLastEvent.getOperation());
    assertEquals(true, this.clLastEvent.isOriginRemote());
    assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
    assertTrue(r.isDestroyed());
  }
  /**
   * check distributed ops that originate in a PROXY are correctly distributed to non-proxy regions.
   */
  private void distributedOps(DataPolicy dp, InterestPolicy ip) throws CacheException {
    initOtherId();
    AttributesFactory af = new AttributesFactory();
    af.setDataPolicy(dp);
    af.setSubscriptionAttributes(new SubscriptionAttributes(ip));
    af.setScope(Scope.DISTRIBUTED_ACK);
    Region r = createRootRegion("ProxyDUnitTest", af.create());

    doCreateOtherVm();

    r.put("putkey", "putvalue1");

    getOtherVm()
        .invoke(
            new CacheSerializableRunnable("check put") {
              public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                assertEquals(true, r.containsKey("putkey"));
                assertEquals("putvalue1", r.getEntry("putkey").getValue());
                r.put("putkey", "putvalue2");
              }
            });

    assertEquals(false, r.containsKey("putkey"));
    assertEquals("putvalue2", r.get("putkey")); // netsearch

    r.invalidate("putkey");

    getOtherVm()
        .invoke(
            new CacheSerializableRunnable("check invalidate") {
              public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                assertEquals(true, r.containsKey("putkey"));
                assertEquals(null, r.getEntry("putkey").getValue());
              }
            });
    assertEquals(null, r.get("putkey")); // invalid so total miss

    r.destroy("putkey");

    getOtherVm()
        .invoke(
            new CacheSerializableRunnable("check destroy") {
              public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                assertEquals(false, r.containsKey("putkey"));
              }
            });

    assertEquals(null, r.get("putkey")); // total miss

    r.create("createKey", "createValue1");
    getOtherVm()
        .invoke(
            new CacheSerializableRunnable("check create") {
              public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                assertEquals(true, r.containsKey("createKey"));
                assertEquals("createValue1", r.getEntry("createKey").getValue());
              }
            });
    {
      Map m = new HashMap();
      m.put("putAllKey1", "putAllValue1");
      m.put("putAllKey2", "putAllValue2");
      r.putAll(m, "putAllCallback");
    }
    getOtherVm()
        .invoke(
            new CacheSerializableRunnable("check putAll") {
              public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                assertEquals(true, r.containsKey("putAllKey1"));
                assertEquals("putAllValue1", r.getEntry("putAllKey1").getValue());
                assertEquals(true, r.containsKey("putAllKey2"));
                assertEquals("putAllValue2", r.getEntry("putAllKey2").getValue());
              }
            });
    r.clear();
    getOtherVm()
        .invoke(
            new CacheSerializableRunnable("check clear") {
              public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                assertEquals(0, r.size());
              }
            });

    getOtherVm()
        .invoke(
            new CacheSerializableRunnable("install CacheWriter") {
              public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                AttributesMutator am = r.getAttributesMutator();
                CacheWriter cw =
                    new CacheWriterAdapter() {
                      public void beforeCreate(EntryEvent event) throws CacheWriterException {
                        throw new CacheWriterException("expected");
                      }
                    };
                am.setCacheWriter(cw);
              }
            });
    try {
      r.put("putkey", "putvalue");
      fail("expected CacheWriterException");
    } catch (CacheWriterException expected) {
    }
    getOtherVm()
        .invoke(
            new CacheSerializableRunnable("check clear") {
              public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                assertEquals(0, r.size());
              }
            });

    assertEquals(null, r.get("loadkey")); // total miss
    getOtherVm()
        .invoke(
            new CacheSerializableRunnable("install CacheLoader") {
              public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                AttributesMutator am = r.getAttributesMutator();
                am.setCacheWriter(null); // clear csche writer
                CacheLoader cl =
                    new CacheLoader() {
                      public Object load(LoaderHelper helper) throws CacheLoaderException {
                        if (helper.getKey().equals("loadkey")) {
                          return "loadvalue";
                        } else if (helper.getKey().equals("loadexception")) {
                          throw new CacheLoaderException("expected");
                        } else {
                          return null;
                        }
                      }

                      public void close() {}
                    };
                am.setCacheLoader(cl);
              }
            });
    assertEquals("loadvalue", r.get("loadkey")); // net load
    assertEquals(null, r.get("foobar")); // total miss
    try {
      r.get("loadexception");
      fail("expected CacheLoaderException");
    } catch (CacheLoaderException expected) {
    }
    r.destroyRegion();
    getOtherVm()
        .invoke(
            new CacheSerializableRunnable("check clear") {
              public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                assertEquals(null, r);
              }
            });
  }