Java Code Examples for com.gemstone.gemfire.cache.Region#getEntry()

The following examples show how to use com.gemstone.gemfire.cache.Region#getEntry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DurableRegistrationDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private static void putValue(String key, String value) {
  try {
    Region r = CacheServerTestUtil.getCache().getRegion(
        DurableRegistrationDUnitTest.class.getName() + "_region");
    // Region r = CacheServerTestUtil.getCache().getRegion(regionName);
    assertNotNull(r);
    if (r.getEntry(key) != null) {
      r.put(key, value);
    }
    else {
      r.create(key, value);
    }
    assertEquals(value, r.getEntry(key).getValue());
  }
  catch (Exception e) {

    fail("Put in Server has some fight");

  }
}
 
Example 2
Source File: PartitionedRegionSingleNodeOperationsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void test022GetEntry() throws Exception {
  Region pr = null;
  try {
    pr = PartitionedRegionTestHelper.createPartitionedRegion("testGetEntry", String.valueOf(200), 0);
    final Integer one = new Integer(1);
    pr.put(one, "one" );
    final Region.Entry re = pr.getEntry(one);
    assertFalse(re.isDestroyed());
    assertFalse(re.isLocal());
    assertTrue(((EntrySnapshot)re).wasInitiallyLocal());

    assertEquals("one", re.getValue());
    assertEquals(one, re.getKey());
    // TODO: Finish out the entry operations
    assertNull(pr.getEntry("nuthin"));
  }
  finally {
    if (pr!=null) {
      pr.destroyRegion();
    }      
  }
}
 
Example 3
Source File: DurableRegistrationDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private static void putValue(String key, String value) {
  try {
    Region r = CacheServerTestUtil.getCache().getRegion(
        DurableRegistrationDUnitTest.class.getName() + "_region");
    // Region r = CacheServerTestUtil.getCache().getRegion(regionName);
    assertNotNull(r);
    if (r.getEntry(key) != null) {
      r.put(key, value);
    }
    else {
      r.create(key, value);
    }
    assertEquals(value, r.getEntry(key).getValue());
  }
  catch (Exception e) {

    fail("Put in Server has some fight");

  }
}
 
Example 4
Source File: InterestListFailoverDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void _validateEntries(final String v)
{
  try {
    final Region r = CacheServerTestUtil.getCache().getRegion("/" + REGION_NAME);
    final String key1 = "key-1";
    assertNotNull(r);
    // Verify that 'key-1' was updated
    // assertEquals("vm2-key-1", r.getEntry("key-1").getValue());
    WaitCriterion wc = new WaitCriterion() {
      String excuse;
      public boolean done() {
        Region.Entry e = r.getEntry(key1);
        if (e == null) {
          return false;
        }
        Object val = e.getValue();
        if (val == null) {
          return false;
        }
        if (!val.equals("vm2-key-1" + v)) {
          return false;
        }
        return true;
      }
      public String description() {
        return excuse;
      }
    };
    DistributedTestCase.waitForCriterion(wc, 40 * 1000, 1000, true);
    
    // Verify that 'key-6' was not invalidated
    assertEquals("key-6", r.getEntry("key-6").getValue());
  }
  catch (Exception ex) {
    fail("failed while r.put()", ex);
  }
}
 
Example 5
Source File: Transactions.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private static void printRegionData(Region<String, String> exampleRegion) {
  Set<String> keySet = new TreeSet<String>(exampleRegion.keySet());
  for (String entryKey: keySet) {
    Region.Entry<String, String> entry = exampleRegion.getEntry(entryKey);
    String entryValue = entry.getValue();
    System.out.println("        entry: " + entryKey + ", " + entryValue);
  }
}
 
Example 6
Source File: InterestListFailoverDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void _validateEntries(final String v)
{
  try {
    final Region r = CacheServerTestUtil.getCache().getRegion("/" + REGION_NAME);
    final String key1 = "key-1";
    assertNotNull(r);
    // Verify that 'key-1' was updated
    // assertEquals("vm2-key-1", r.getEntry("key-1").getValue());
    WaitCriterion wc = new WaitCriterion() {
      String excuse;
      public boolean done() {
        Region.Entry e = r.getEntry(key1);
        if (e == null) {
          return false;
        }
        Object val = e.getValue();
        if (val == null) {
          return false;
        }
        if (!val.equals("vm2-key-1" + v)) {
          return false;
        }
        return true;
      }
      public String description() {
        return excuse;
      }
    };
    DistributedTestCase.waitForCriterion(wc, 40 * 1000, 1000, true);
    
    // Verify that 'key-6' was not invalidated
    assertEquals("key-6", r.getEntry("key-6").getValue());
  }
  catch (Exception ex) {
    fail("failed while r.put()", ex);
  }
}
 
Example 7
Source File: GetEntry70.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public Get70.Entry getValueAndIsObject(Region region, Object key,
    Object callbackArg, LogWriterI18n log,
    ServerConnection servConn) {
  LocalRegion lregion = (LocalRegion)region;
  Object data = null;
  Region.Entry entry = region.getEntry(key);
  if (logger.fineEnabled()) {
    logger.fine("GetEntryCommand: for key:"+key+" returning entry:"+entry);
  }
  VersionTag tag = null;
  if (entry != null) {
    EntrySnapshot snap;
    if (entry instanceof EntrySnapshot) {
      snap = (EntrySnapshot)entry;
      tag = snap.getVersionTag();
    }
    else {
      snap = new EntrySnapshot();
    }
    NonLocalRegionEntry re = NonLocalRegionEntry.newEntry(key,
        entry.getValue(), lregion, tag);
    snap.setRegionEntry(re);
    snap.setRegion(lregion);
    data = snap;
  }
  Get70.Entry result = new Get70.Entry();
  result.value = data;
  result.isObject = true;
  result.keyNotPresent = false;
  result.versionTag = tag;
  return result;
}
 
Example 8
Source File: HAInterestBaseTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void verifyRefreshedEntriesFromServer()
{
  final Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
  assertNotNull(r1);
  
  WaitCriterion wc = new WaitCriterion() {
    String excuse;
    public boolean done() {
      Region.Entry re = r1.getEntry(k1);
      if (re == null) return false;
      Object val = re.getValue();
      return client_k1.equals(val);
    }
    public String description() {
      return excuse;
    }
  };
  DistributedTestCase.waitForCriterion(wc, MAX_WAIT, 1000, true);

  wc = new WaitCriterion() {
    String excuse;
    public boolean done() {
      Region.Entry re = r1.getEntry(k2);
      if (re == null) return false;
      Object val = re.getValue();
      return client_k2.equals(val);
    }
    public String description() {
      return excuse;
    }
  };
  DistributedTestCase.waitForCriterion(wc, MAX_WAIT, 1000, true);

  // assertEquals(client_k1, r1.getEntry(k1).getValue());
  // assertEquals(client_k2 ,r1.getEntry(k2).getValue());
}
 
Example 9
Source File: HAInterestBaseTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void verifyRefreshedEntriesFromServer()
{
  final Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
  assertNotNull(r1);
  
  WaitCriterion wc = new WaitCriterion() {
    String excuse;
    public boolean done() {
      Region.Entry re = r1.getEntry(k1);
      if (re == null) return false;
      Object val = re.getValue();
      return client_k1.equals(val);
    }
    public String description() {
      return excuse;
    }
  };
  DistributedTestCase.waitForCriterion(wc, MAX_WAIT, 1000, true);

  wc = new WaitCriterion() {
    String excuse;
    public boolean done() {
      Region.Entry re = r1.getEntry(k2);
      if (re == null) return false;
      Object val = re.getValue();
      return client_k2.equals(val);
    }
    public String description() {
      return excuse;
    }
  };
  DistributedTestCase.waitForCriterion(wc, MAX_WAIT, 1000, true);

  // assertEquals(client_k1, r1.getEntry(k1).getValue());
  // assertEquals(client_k2 ,r1.getEntry(k2).getValue());
}
 
Example 10
Source File: InterestListDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void validateRegionEntriesFromInterestListInVm1()
{
  Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME);
  assertNotNull(r);
  Region.Entry k1, k2;
  k1 = r.getEntry("k1");
  k2 = r.getEntry("k2");
  assertNotNull(k1);
  assertNotNull(k2);
  assertEquals(k1.getValue(), "server1");
  assertEquals(k2.getValue(), "server2");
}
 
Example 11
Source File: InterestListDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void validateRegionEntriesFromInterestListInVm1()
{
  Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME);
  assertNotNull(r);
  Region.Entry k1, k2;
  k1 = r.getEntry("k1");
  k2 = r.getEntry("k2");
  assertNotNull(k1);
  assertNotNull(k2);
  assertEquals(k1.getValue(), "server1");
  assertEquals(k2.getValue(), "server2");
}
 
Example 12
Source File: HAInterestPart2DUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Bug Test for Bug # 35945
 * A java level Deadlock between acquireConnection and RegionEntry
 * during processRecoveredEndpoint by Dead Server Monitor Thread.
 *
 * @throws Exception
 */
public void testBug35945()throws Exception{

  PORT1 =  ((Integer) server1.invoke(HAInterestBaseTest.class, "createServerCache")).intValue();
  server1.invoke(HAInterestBaseTest.class, "createEntriesK1andK2");
  createClientPoolCacheConnectionToSingleServer(this.getName(),getServerHostName(server1.getHost()));
  registerK1AndK2();
  verifyRefreshedEntriesFromServer();

  server1.invoke(HAInterestBaseTest.class, "stopServer");
  verifyDeadAndLiveServers(1, 0);
  // put on stopped server
  server1.invoke(HAInterestBaseTest.class, "putK1andK2");
  // spawn a thread to put on server , which will acquire a lock on entry 
  setBridgeObserverForBeforeInterestRecovery();
  server1.invoke(HAInterestBaseTest.class, "startServer");
  verifyDeadAndLiveServers(0, 1);
  waitForBeforeInterestRecoveryCallBack();
  // verify updated value of k1 as a refreshEntriesFromServer
  final Region r1 = cache.getRegion(Region.SEPARATOR+ REGION_NAME);
  assertNotNull(r1);
  
  WaitCriterion wc = new WaitCriterion() {
    String excuse;
    public boolean done() {
      Region.Entry e1 = r1.getEntry(k1);
      Region.Entry e2 = r1.getEntry(k2);
      if (e1 == null || !server_k1_updated.equals(e1.getValue())) {
        return false;
      }
      if (e2 == null || !server_k2.equals(e2.getValue())) {
        return false;
      }
      return true;
    }
    public String description() {
      return excuse;
    }
  };
  DistributedTestCase.waitForCriterion(wc, 2 * 60 * 1000, 1000, true);
 // assertEquals(server_k2, r1.getEntry(k2).getValue());
 // assertEquals(server_k1_updated ,r1.getEntry(k1).getValue());
}
 
Example 13
Source File: HAInterestPart2DUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
  * Tests if failure occured in Interest recovery thread, then it should select new endpoint to
  * register interest
  *
  * @throws Exception
  */
 public void testInterestRecoveryFailure()throws Exception{

  PORT1 =  ((Integer) server1.invoke(HAInterestBaseTest.class, "createServerCache")).intValue();
  server1.invoke(HAInterestBaseTest.class, "createEntriesK1andK2");
  PORT2 =  ((Integer) server2.invoke(HAInterestBaseTest.class, "createServerCache")).intValue();
  server2.invoke(HAInterestBaseTest.class, "createEntriesK1andK2");
  createClientPoolCacheWithSmallRetryInterval(this.getName(),getServerHostName(server1.getHost()));
  registerK1AndK2();
  verifyRefreshedEntriesFromServer();
  VM backup = getBackupVM();
  VM primary = getPrimaryVM();
  cache.getLogger().info("<ExpectedException action=add>" + "Server unreachable" +
      "</ExpectedException>");
  try {
    backup.invoke(HAInterestBaseTest.class, "stopServer");
    primary.invoke(HAInterestBaseTest.class, "stopServer");
    verifyDeadAndLiveServers(2, 0);
  } finally {
    cache.getLogger().info("<ExpectedException action=remove>" + "Server unreachable" +
        "</ExpectedException>");
  }
  primary.invoke(HAInterestBaseTest.class, "putK1andK2");
  setBridgeObserverForBeforeInterestRecoveryFailure();
  primary.invoke(HAInterestBaseTest.class, "startServer");
  waitForBeforeInterestRecoveryCallBack();
  if(exceptionOccured) {
    fail("The DSM could not ensure that server 1 is started & serevr 2 is stopped");
  }
  final Region r1 = cache.getRegion(Region.SEPARATOR+ REGION_NAME);
  assertNotNull(r1);
  //pause(10000);
  WaitCriterion wc = new WaitCriterion() {
    String excuse;
    public boolean done() {
      Region.Entry e1 = r1.getEntry(k1);
      Region.Entry e2 = r1.getEntry(k2);
      if (e1 == null) {
        excuse = "Entry for k1 still null";
        return false;
      }
      if (e2 == null) {
        excuse = "Entry for k2 still null";
        return false;
      }
      if (!(server_k1.equals(e1.getValue()))) {
        excuse = "Value for k1 wrong";
        return false;
      }
      if (!(server_k2.equals(e2.getValue()))) {
        excuse = "Value for k2 wrong";
        return false;
      }
      return true;
    }
    public String description() {
      return excuse;
    }
  };
  DistributedTestCase.waitForCriterion(wc, 2 * 60 * 1000, 1000, true);
}
 
Example 14
Source File: UpdateVersionJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testUpdateVersionAfterUpdateOnPR() {
  Cache cache = new CacheFactory().create();
  Region region = cache.createRegionFactory(RegionShortcut.PARTITION).create(regionName);

  try {
    region.create("key-1", "value-1");
    try {
      Thread.sleep(10);
    } catch (InterruptedException e) { }
    region.put("key-1", "value-2");

    Entry entry = region.getEntry("key-1");
    assertTrue(entry instanceof EntrySnapshot);
    RegionEntry regionEntry = ((EntrySnapshot)entry).getRegionEntry();

    VersionStamp stamp = regionEntry.getVersionStamp();

    // Create a duplicate entry version tag from stamp with newer time-stamp.
    VersionTag tag = VersionTag.create(stamp.getMemberID());

    int entryVersion = stamp.getEntryVersion();
    VersionSource member = stamp.getMemberID();
    int dsid = stamp.getDistributedSystemId();
    long time = System.currentTimeMillis();
    
    tag.setEntryVersion(entryVersion);
    tag.setDistributedSystemId(dsid);
    tag.setVersionTimeStamp(time);
    tag.setIsGatewayTag(true);

    assertTrue(region instanceof PartitionedRegion);
    
    EntryEventImpl event = createNewEvent((PartitionedRegion)region, tag, entry.getKey());
    
    ((PartitionedRegion)region).basicUpdateEntryVersion(event);

    // Verify the new stamp
    entry = region.getEntry("key-1");
    assertTrue(entry instanceof EntrySnapshot);
    regionEntry = ((EntrySnapshot)entry).getRegionEntry();

    stamp = regionEntry.getVersionStamp();
    assertEquals(
        "Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion",
        time, stamp.getVersionTimeStamp());
    assertEquals(++entryVersion, stamp.getEntryVersion());
    assertEquals(member, stamp.getMemberID());
    assertEquals(dsid, stamp.getDistributedSystemId());
  } finally {
    region.destroyRegion();
    cache.close();
  }
}
 
Example 15
Source File: UpdateVersionJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Tests for LocalRegion.
 */

public void testUpdateVersionAfterCreate() {
  
  Cache cache = new CacheFactory().create();
  Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);

  try {
    region.create("key-1", "value-1");

    Entry entry = region.getEntry("key-1");
    assertTrue(entry instanceof NonTXEntry);
    RegionEntry regionEntry = ((NonTXEntry)entry).getRegionEntry();

    VersionStamp stamp = regionEntry.getVersionStamp();

    // Create a duplicate entry version tag from stamp with newer time-stamp.
    VersionTag tag = VersionTag.create(stamp.getMemberID());

    int entryVersion = stamp.getEntryVersion();
    VersionSource member = stamp.getMemberID();
    int dsid = stamp.getDistributedSystemId();
    long time = System.currentTimeMillis() + 1;
    
    tag.setEntryVersion(entryVersion);
    tag.setDistributedSystemId(dsid);
    tag.setVersionTimeStamp(time);
    tag.setIsGatewayTag(true);

    assertTrue(region instanceof LocalRegion);
    
    EntryEventImpl event = createNewEvent((LocalRegion)region, tag, entry.getKey());
    
    ((LocalRegion)region).basicUpdateEntryVersion(event);

    // Verify the new stamp
    entry = region.getEntry("key-1");
    assertTrue(entry instanceof NonTXEntry);
    regionEntry = ((NonTXEntry)entry).getRegionEntry();

    stamp = regionEntry.getVersionStamp();
    assertEquals(
        "Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion",
        time, stamp.getVersionTimeStamp());
    assertEquals(++entryVersion, stamp.getEntryVersion());
    assertEquals(member, stamp.getMemberID());
    assertEquals(dsid, stamp.getDistributedSystemId());
  } finally {
    region.destroyRegion();
    cache.close();
  }
}
 
Example 16
Source File: UpdateVersionJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testUpdateVersionAfterUpdate() {
  Cache cache = new CacheFactory().create();
  Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);

  try {
    region.create("key-1", "value-1");
    try {
      Thread.sleep(10);
    } catch (InterruptedException e) { }
    region.put("key-1", "value-2");

    Entry entry = region.getEntry("key-1");
    assertTrue(entry instanceof NonTXEntry);
    RegionEntry regionEntry = ((NonTXEntry)entry).getRegionEntry();

    VersionStamp stamp = regionEntry.getVersionStamp();

    // Create a duplicate entry version tag from stamp with newer time-stamp.
    VersionTag tag = VersionTag.create(stamp.getMemberID());

    int entryVersion = stamp.getEntryVersion();
    VersionSource member = stamp.getMemberID();
    int dsid = stamp.getDistributedSystemId();
    long time = System.currentTimeMillis() + 1; // Just in case if clock hasn't ticked.
    
    tag.setEntryVersion(entryVersion);
    tag.setDistributedSystemId(dsid);
    tag.setVersionTimeStamp(time);
    tag.setIsGatewayTag(true);
    
    assertTrue(region instanceof LocalRegion);
    
    EntryEventImpl event = createNewEvent((LocalRegion)region, tag, entry.getKey());
    
    ((LocalRegion)region).basicUpdateEntryVersion(event);

    // Verify the new stamp
    entry = region.getEntry("key-1");
    assertTrue(entry instanceof NonTXEntry);
    regionEntry = ((NonTXEntry)entry).getRegionEntry();

    stamp = regionEntry.getVersionStamp();
    assertEquals(
        "Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion",
        time, stamp.getVersionTimeStamp());
    assertEquals(++entryVersion, stamp.getEntryVersion());
    assertEquals(member, stamp.getMemberID());
    assertEquals(dsid, stamp.getDistributedSystemId());
  } finally {
    region.destroyRegion();
    cache.close();
  }
}
 
Example 17
Source File: UpdateVersionJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testUpdateVersionAfterUpdateOnPR() {
  Cache cache = new CacheFactory().create();
  Region region = cache.createRegionFactory(RegionShortcut.PARTITION).create(regionName);

  try {
    region.create("key-1", "value-1");
    try {
      Thread.sleep(10);
    } catch (InterruptedException e) { }
    region.put("key-1", "value-2");

    Entry entry = region.getEntry("key-1");
    assertTrue(entry instanceof EntrySnapshot);
    RegionEntry regionEntry = ((EntrySnapshot)entry).getRegionEntry();

    VersionStamp stamp = regionEntry.getVersionStamp();

    // Create a duplicate entry version tag from stamp with newer time-stamp.
    VersionTag tag = VersionTag.create(stamp.getMemberID());

    int entryVersion = stamp.getEntryVersion();
    VersionSource member = stamp.getMemberID();
    int dsid = stamp.getDistributedSystemId();
    long time = System.currentTimeMillis();
    
    tag.setEntryVersion(entryVersion);
    tag.setDistributedSystemId(dsid);
    tag.setVersionTimeStamp(time);
    tag.setIsGatewayTag(true);

    assertTrue(region instanceof PartitionedRegion);
    
    EntryEventImpl event = createNewEvent((PartitionedRegion)region, tag, entry.getKey());
    
    ((PartitionedRegion)region).basicUpdateEntryVersion(event);

    // Verify the new stamp
    entry = region.getEntry("key-1");
    assertTrue(entry instanceof EntrySnapshot);
    regionEntry = ((EntrySnapshot)entry).getRegionEntry();

    stamp = regionEntry.getVersionStamp();
    assertEquals(
        "Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion",
        time, stamp.getVersionTimeStamp());
    assertEquals(++entryVersion, stamp.getEntryVersion());
    assertEquals(member, stamp.getMemberID());
    assertEquals(dsid, stamp.getDistributedSystemId());
  } finally {
    region.destroyRegion();
    cache.close();
  }
}
 
Example 18
Source File: UpdateVersionJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testUpdateVersionAfterUpdate() {
  Cache cache = new CacheFactory().create();
  Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);

  try {
    region.create("key-1", "value-1");
    try {
      Thread.sleep(10);
    } catch (InterruptedException e) { }
    region.put("key-1", "value-2");

    Entry entry = region.getEntry("key-1");
    assertTrue(entry instanceof NonTXEntry);
    RegionEntry regionEntry = ((NonTXEntry)entry).getRegionEntry();

    VersionStamp stamp = regionEntry.getVersionStamp();

    // Create a duplicate entry version tag from stamp with newer time-stamp.
    VersionTag tag = VersionTag.create(stamp.getMemberID());

    int entryVersion = stamp.getEntryVersion();
    VersionSource member = stamp.getMemberID();
    int dsid = stamp.getDistributedSystemId();
    long time = System.currentTimeMillis() + 1; // Just in case if clock hasn't ticked.
    
    tag.setEntryVersion(entryVersion);
    tag.setDistributedSystemId(dsid);
    tag.setVersionTimeStamp(time);
    tag.setIsGatewayTag(true);
    
    assertTrue(region instanceof LocalRegion);
    
    EntryEventImpl event = createNewEvent((LocalRegion)region, tag, entry.getKey());
    
    ((LocalRegion)region).basicUpdateEntryVersion(event);

    // Verify the new stamp
    entry = region.getEntry("key-1");
    assertTrue(entry instanceof NonTXEntry);
    regionEntry = ((NonTXEntry)entry).getRegionEntry();

    stamp = regionEntry.getVersionStamp();
    assertEquals(
        "Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion",
        time, stamp.getVersionTimeStamp());
    assertEquals(++entryVersion, stamp.getEntryVersion());
    assertEquals(member, stamp.getMemberID());
    assertEquals(dsid, stamp.getDistributedSystemId());
  } finally {
    region.destroyRegion();
    cache.close();
  }
}
 
Example 19
Source File: PartitionedRegionSingleNodeOperationsJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void test023UnsupportedOps() throws Exception {
    Region pr = null;
    try {
      pr = PartitionedRegionTestHelper.createPartitionedRegion("testUnsupportedOps", String.valueOf(200), 0);
      
      pr.put(new Integer(1), "one" );
      pr.put(new Integer(2), "two" );
      pr.put(new Integer(3), "three" );
      pr.getEntry("key");
      
      try {
        pr.clear();
        fail("PartitionedRegionSingleNodeOperationTest:testUnSupportedOps() operation failed on a blank PartitionedRegion");
      }
      catch (UnsupportedOperationException expected) {
      }
      
//      try {
//        pr.entries(true);
//        fail();
//      }
//      catch (UnsupportedOperationException expected) {
//      }
      
//      try {
//        pr.entrySet(true);
//        fail();
//      }
//      catch (UnsupportedOperationException expected) {
//      }
      
      try {
        HashMap data = new HashMap();
        data.put("foo", "bar");
        data.put("bing", "bam");
        data.put("supper", "hero");
        pr.putAll(data);
//        fail("testPutAll() does NOT throw UnsupportedOperationException");
      }
      catch (UnsupportedOperationException onse) {
      }
      
      
//      try {
//        pr.values();
//        fail("testValues() does NOT throw UnsupportedOperationException");
//      }
//      catch (UnsupportedOperationException expected) {
//      }

      
      try {
        pr.containsValue("foo");
      }
      catch (UnsupportedOperationException ex) {
        fail("PartitionedRegionSingleNodeOperationTest:testContainsValue() operation failed");
      }
      
    } finally {
      if (pr!=null) {
        pr.destroyRegion();
      }
    }
  }
 
Example 20
Source File: UpdateVersionJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Tests for LocalRegion.
 */

public void testUpdateVersionAfterCreate() {
  
  Cache cache = new CacheFactory().create();
  Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);

  try {
    region.create("key-1", "value-1");

    Entry entry = region.getEntry("key-1");
    assertTrue(entry instanceof NonTXEntry);
    RegionEntry regionEntry = ((NonTXEntry)entry).getRegionEntry();

    VersionStamp stamp = regionEntry.getVersionStamp();

    // Create a duplicate entry version tag from stamp with newer time-stamp.
    VersionTag tag = VersionTag.create(stamp.getMemberID());

    int entryVersion = stamp.getEntryVersion();
    VersionSource member = stamp.getMemberID();
    int dsid = stamp.getDistributedSystemId();
    long time = System.currentTimeMillis() + 1;
    
    tag.setEntryVersion(entryVersion);
    tag.setDistributedSystemId(dsid);
    tag.setVersionTimeStamp(time);
    tag.setIsGatewayTag(true);

    assertTrue(region instanceof LocalRegion);
    
    EntryEventImpl event = createNewEvent((LocalRegion)region, tag, entry.getKey());
    
    ((LocalRegion)region).basicUpdateEntryVersion(event);

    // Verify the new stamp
    entry = region.getEntry("key-1");
    assertTrue(entry instanceof NonTXEntry);
    regionEntry = ((NonTXEntry)entry).getRegionEntry();

    stamp = regionEntry.getVersionStamp();
    assertEquals(
        "Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion",
        time, stamp.getVersionTimeStamp());
    assertEquals(++entryVersion, stamp.getEntryVersion());
    assertEquals(member, stamp.getMemberID());
    assertEquals(dsid, stamp.getDistributedSystemId());
  } finally {
    region.destroyRegion();
    cache.close();
  }
}