Search in sources :

Example 36 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class GIIDeltaDUnitTest method getDistributedMemberID.

// private VersionTag getVersionTag(VM vm, final String key) {
// SerializableCallable getVersionTag = new SerializableCallable("verify recovered entry") {
// public Object call() {
// VersionTag tag = CCRegion.getVersionTag(key);
// return tag;
//
// }
// };
// return (VersionTag)vm.invoke(getVersionTag);
// }
public InternalDistributedMember getDistributedMemberID(VM vm) {
    SerializableCallable getID = new SerializableCallable("get member id") {

        public Object call() {
            return getCache().getDistributedSystem().getDistributedMember();
        }
    };
    InternalDistributedMember id = (InternalDistributedMember) vm.invoke(getID);
    return id;
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember)

Example 37 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class TombstoneCreationJUnitTest method testDestroyCreatesTombstone.

@Test
public void testDestroyCreatesTombstone() throws Exception {
    String name = nameRule.getMethodName();
    Properties props = new Properties();
    props.put(LOCATORS, "");
    props.put(MCAST_PORT, "0");
    props.put(LOG_LEVEL, "config");
    GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.create(DistributedSystem.connect(props));
    RegionFactory f = cache.createRegionFactory(RegionShortcut.REPLICATE);
    DistributedRegion region = (DistributedRegion) f.create(name);
    EntryEventImpl ev = EntryEventImpl.create(region, Operation.DESTROY, "myDestroyedKey", null, null, true, new InternalDistributedMember(InetAddress.getLocalHost(), 1234));
    VersionTag tag = VersionTag.create((InternalDistributedMember) ev.getDistributedMember());
    tag.setIsRemoteForTesting();
    tag.setEntryVersion(2);
    tag.setRegionVersion(12345);
    tag.setVersionTimeStamp(System.currentTimeMillis());
    tag.setDistributedSystemId(1);
    ev.setVersionTag(tag);
    cache.getLogger().info("destroyThread is trying to destroy the entry: " + region.getRegionEntry("myDestroyedKey"));
    // expectedOldValue not supported on
    region.basicDestroy(ev, false, null);
    RegionEntry entry = region.getRegionEntry("myDestroyedKey");
    Assert.assertTrue(entry != null, "expected to find a region entry for myDestroyedKey");
    Assert.assertTrue(entry.isTombstone(), "expected entry to be found and be a tombstone but it is " + entry);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 38 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class TombstoneCreationJUnitTest method testConcurrentCreateAndDestroy.

/**
   * In bug #47868 a thread puts a REMOVED_PHASE1 entry in the map but is unable to lock the entry
   * before a Destroy thread gets it. The Destroy thread did not apply its operation but threw an
   * EntryNotFoundException. It is supposed to create a Tombstone.
   * 
   * @throws Exception
   */
@Test
public void testConcurrentCreateAndDestroy() throws Exception {
    String name = nameRule.getMethodName();
    Properties props = new Properties();
    props.put(LOCATORS, "");
    props.put(MCAST_PORT, "0");
    props.put(LOG_LEVEL, "config");
    final GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.create(DistributedSystem.connect(props));
    RegionFactory f = cache.createRegionFactory(RegionShortcut.REPLICATE);
    final DistributedRegion region = (DistributedRegion) f.create(name);
    // simulate a put() getting into AbstractRegionMap.basicPut() and creating an entry
    // that has not yet been initialized with values. Then do a destroy that will encounter
    // the entry
    String key = "destroyedKey1";
    VersionedThinRegionEntryHeap entry = new VersionedThinRegionEntryHeapObjectKey(region, key, Token.REMOVED_PHASE1);
    ((AbstractRegionMap) region.getRegionMap()).putEntryIfAbsentForTest(entry);
    cache.getLogger().info("entry inserted into cache: " + entry);
    EntryEventImpl ev = EntryEventImpl.create(region, Operation.DESTROY, key, null, null, true, new InternalDistributedMember(InetAddress.getLocalHost(), 1234));
    VersionTag tag = VersionTag.create((InternalDistributedMember) ev.getDistributedMember());
    tag.setIsRemoteForTesting();
    tag.setEntryVersion(2);
    tag.setRegionVersion(12345);
    tag.setVersionTimeStamp(System.currentTimeMillis());
    tag.setDistributedSystemId(1);
    ev.setVersionTag(tag);
    cache.getLogger().info("destroyThread is trying to destroy the entry: " + region.getRegionEntry(key));
    // expectedOldValue not supported on
    region.basicDestroy(ev, false, null);
    entry = (VersionedThinRegionEntryHeap) region.getRegionEntry(key);
    region.dumpBackingMap();
    Assert.assertTrue(entry != null, "expected to find a region entry for " + key);
    Assert.assertTrue(entry.isTombstone(), "expected entry to be found and be a tombstone but it is " + entry);
    Assert.assertTrue(entry.getVersionStamp().getEntryVersion() == tag.getEntryVersion(), "expected " + tag.getEntryVersion() + " but found " + entry.getVersionStamp().getEntryVersion());
    RegionMap map = region.getRegionMap();
    tag = entry.asVersionTag();
    map.removeTombstone(entry, tag, false, true);
    // now do an op that has local origin
    entry = new VersionedThinRegionEntryHeapObjectKey(region, key, Token.REMOVED_PHASE1);
    ((AbstractRegionMap) region.getRegionMap()).putEntryIfAbsentForTest(entry);
    cache.getLogger().info("entry inserted into cache: " + entry);
    ev = EntryEventImpl.create(region, Operation.DESTROY, key, null, null, false, cache.getMyId());
    tag = VersionTag.create((InternalDistributedMember) ev.getDistributedMember());
    tag.setEntryVersion(2);
    tag.setRegionVersion(12345);
    tag.setVersionTimeStamp(System.currentTimeMillis());
    tag.setDistributedSystemId(1);
    ev.setVersionTag(tag);
    cache.getLogger().info("destroyThread is trying to destroy the entry: " + region.getRegionEntry(key));
    boolean caught = false;
    try {
        // expectedOldValue not supported on
        region.basicDestroy(ev, false, null);
    } catch (EntryNotFoundException e) {
        caught = true;
    }
    Assert.assertTrue(caught, "expected an EntryNotFoundException for origin=local destroy operation");
}
Also used : ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 39 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class TXMessageTest method shouldBeMockable.

@Test
public void shouldBeMockable() throws Exception {
    TXMessage mockTXMessage = mock(TXMessage.class);
    InternalDistributedMember mockInternalDistributedMember = mock(InternalDistributedMember.class);
    when(mockTXMessage.getMemberToMasqueradeAs()).thenReturn(mockInternalDistributedMember);
    assertThat(mockTXMessage.getMemberToMasqueradeAs()).isSameAs(mockInternalDistributedMember);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 40 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class MemberFunctionExecutionDUnitTest method excuteOnMembers_InlineFunction.

/*
   * Execute Function
   */
public static void excuteOnMembers_InlineFunction(Integer noOfMembers) {
    assertNotNull(ds);
    Execution memberExcution = null;
    if (noOfMembers.intValue() == 1) {
        // Local VM
        DistributedMember localmember = ds.getDistributedMember();
        memberExcution = FunctionService.onMember(localmember);
    } else if (noOfMembers.intValue() == 5) {
        memberExcution = FunctionService.onMembers();
    } else {
        Set memberSet = new HashSet(ds.getDistributionManager().getNormalDistributionManagerIds());
        InternalDistributedMember localVM = ds.getDistributionManager().getDistributionManagerId();
        memberSet.remove(localVM);
        memberExcution = FunctionService.onMembers(memberSet);
    }
    Execution executor = memberExcution.setArguments("Key");
    try {
        ResultCollector rc = executor.execute(new FunctionAdapter() {

            @Override
            public void execute(FunctionContext context) {
                if (context.getArguments() instanceof String) {
                    context.getResultSender().lastResult("Success");
                } else {
                    context.getResultSender().lastResult("Failure");
                }
            }

            @Override
            public String getId() {
                return getClass().getName();
            }

            @Override
            public boolean hasResult() {
                return true;
            }
        });
        List li = (ArrayList) rc.getResult();
        LogWriterUtils.getLogWriter().info("MemberFunctionExecutionDUnitTest#excuteOnMembers: Result : " + li);
        assertEquals(li.size(), noOfMembers.intValue());
        for (Object obj : li) {
            assertEquals(obj, "Success");
        }
    } catch (Exception e) {
        LogWriterUtils.getLogWriter().info("Exception Occurred : " + e.getMessage());
        e.printStackTrace();
        Assert.fail("Test failed", e);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) FunctionContext(org.apache.geode.cache.execute.FunctionContext) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) Execution(org.apache.geode.cache.execute.Execution) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) FunctionAdapter(org.apache.geode.cache.execute.FunctionAdapter) ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet)

Aggregations

InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)516 Test (org.junit.Test)162 HashSet (java.util.HashSet)124 Set (java.util.Set)77 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)63 NetView (org.apache.geode.distributed.internal.membership.NetView)60 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)56 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)55 ArrayList (java.util.ArrayList)54 DistributedMember (org.apache.geode.distributed.DistributedMember)49 UnitTest (org.apache.geode.test.junit.categories.UnitTest)49 HashMap (java.util.HashMap)46 IOException (java.io.IOException)36 Iterator (java.util.Iterator)34 PartitionedRegionLoadModel (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel)34 CompositeDirector (org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector)33 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)32 Map (java.util.Map)29 CancelException (org.apache.geode.CancelException)29 DM (org.apache.geode.distributed.internal.DM)29