Search in sources :

Example 1 with PersistentMemberID

use of org.apache.geode.internal.cache.persistence.PersistentMemberID in project geode by apache.

the class DistributedCacheOperationTest method shouldBeMockable.

@Test
public void shouldBeMockable() throws Exception {
    DistributedCacheOperation mockDistributedCacheOperation = mock(DistributedCacheOperation.class);
    CacheOperationMessage mockCacheOperationMessage = mock(CacheOperationMessage.class);
    Map<InternalDistributedMember, PersistentMemberID> persistentIds = new HashMap<>();
    when(mockDistributedCacheOperation.supportsDirectAck()).thenReturn(false);
    mockDistributedCacheOperation.waitForAckIfNeeded(mockCacheOperationMessage, persistentIds);
    verify(mockDistributedCacheOperation, times(1)).waitForAckIfNeeded(mockCacheOperationMessage, persistentIds);
    assertThat(mockDistributedCacheOperation.supportsDirectAck()).isFalse();
}
Also used : CacheOperationMessage(org.apache.geode.internal.cache.DistributedCacheOperation.CacheOperationMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) HashMap(java.util.HashMap) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 2 with PersistentMemberID

use of org.apache.geode.internal.cache.persistence.PersistentMemberID in project geode by apache.

the class PartitionedRegionLoadModelJUnitTest method testRedundancySatisficationWithOfflineMembers.

/**
   * Test to make sure than redundancy satisfaction ignores offline members
   */
@Test
public void testRedundancySatisficationWithOfflineMembers() throws Exception {
    PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(bucketOperator, 1, 5, getAddressComparor(false), Collections.<InternalDistributedMember>emptySet(), null);
    InternalDistributedMember member1 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 1);
    InternalDistributedMember member2 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 2);
    PartitionMemberInfoImpl details1 = buildDetails(member1, 200, 200, new long[] { 30, 0, 28, 30, 23 }, new long[] { 1, 0, 1, 1, 1 });
    PartitionMemberInfoImpl details2 = buildDetails(member2, 200, 200, new long[] { 0, 23, 0, 0, 0 }, new long[] { 0, 1, 0, 0, 0 });
    // Two buckets have an offline members
    Set<PersistentMemberID> o = Collections.singleton(new PersistentMemberID());
    Set<PersistentMemberID> x = Collections.emptySet();
    final OfflineMemberDetailsImpl offlineDetails = new OfflineMemberDetailsImpl(new Set[] { x, x, o, o, x });
    model.addRegion("primary", Arrays.asList(details1, details2), offlineDetails, true);
    assertEquals(3, doMoves(new CompositeDirector(true, true, false, false), model));
    List<Create> expectedCreates = new ArrayList<Create>();
    expectedCreates.add(new Create(member2, 0));
    expectedCreates.add(new Create(member1, 1));
    expectedCreates.add(new Create(member2, 4));
    assertEquals(expectedCreates, bucketOperator.creates);
}
Also used : PartitionedRegionLoadModel(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ArrayList(java.util.ArrayList) CompositeDirector(org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 3 with PersistentMemberID

use of org.apache.geode.internal.cache.persistence.PersistentMemberID in project geode by apache.

the class PartitionedRegionLoadModelJUnitTest method testRebalancingWithOfflineMembers.

@Test
public void testRebalancingWithOfflineMembers() throws Exception {
    PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(bucketOperator, 1, 6, getAddressComparor(false), Collections.<InternalDistributedMember>emptySet(), null);
    InternalDistributedMember member1 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 1);
    InternalDistributedMember member2 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 2);
    PartitionMemberInfoImpl details1 = buildDetails(member1, 480, 480, new long[] { 1, 1, 1, 1, 1, 1 }, new long[] { 1, 1, 1, 1, 1, 1 });
    PartitionMemberInfoImpl details2 = buildDetails(member2, 480, 480, new long[] { 0, 0, 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0, 0, 0 });
    // Each bucket has an offline member
    Set<PersistentMemberID> o = Collections.singleton(new PersistentMemberID());
    Set<PersistentMemberID> x = Collections.emptySet();
    final OfflineMemberDetailsImpl offlineDetails = new OfflineMemberDetailsImpl(new Set[] { o, o, o, o, o, o });
    model.addRegion("primary", Arrays.asList(details1, details2), offlineDetails, true);
    assertEquals(3, doMoves(new CompositeDirector(true, true, true, true), model));
    List<Move> expectedMoves = new ArrayList<Move>();
    expectedMoves.add(new Move(member1, member2));
    expectedMoves.add(new Move(member1, member2));
    expectedMoves.add(new Move(member1, member2));
    assertEquals(expectedMoves, bucketOperator.bucketMoves);
}
Also used : PartitionedRegionLoadModel(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ArrayList(java.util.ArrayList) CompositeDirector(org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 4 with PersistentMemberID

use of org.apache.geode.internal.cache.persistence.PersistentMemberID in project geode by apache.

the class OfflineMembersDetailsJUnitTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    Set<PersistentMemberID>[] offlineMembers = new Set[5];
    for (int i = 0; i < offlineMembers.length; i++) {
        offlineMembers[i] = new HashSet<PersistentMemberID>();
        offlineMembers[i].add(new PersistentMemberID(DiskStoreID.random(), InetAddress.getLocalHost(), "a", System.currentTimeMillis(), (short) 0));
    }
    OfflineMemberDetailsImpl details = new OfflineMemberDetailsImpl(offlineMembers);
    ByteArrayOutputStream boas = new ByteArrayOutputStream();
    DataOutput out = new DataOutputStream(boas);
    details.toData(out);
    OfflineMemberDetailsImpl details2 = new OfflineMemberDetailsImpl();
    details2.fromData(new DataInputStream(new ByteArrayInputStream(boas.toByteArray())));
}
Also used : DataOutput(java.io.DataOutput) Set(java.util.Set) HashSet(java.util.HashSet) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 5 with PersistentMemberID

use of org.apache.geode.internal.cache.persistence.PersistentMemberID in project geode by apache.

the class DiskIFJUnitTest method testEmptyIF.

@Test
public void testEmptyIF() throws Exception {
    diskProps.setPersistBackup(true);
    diskProps.setRegionName("testEmptyIF");
    LocalRegion lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    DiskRegion dr = lr.getDiskRegion();
    assertEquals(null, dr.getMyInitializingID());
    PersistentMemberID myId = dr.getMyPersistentID();
    assertNotNull(myId);
    assertTrue(dr.getOnlineMembers().isEmpty());
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertTrue(dr.getOfflineAndEqualMembers().isEmpty());
    // do recovery
    close(lr);
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertEquals(null, dr.getMyInitializingID());
    assertEquals(myId, dr.getMyPersistentID());
    assertTrue(dr.getOnlineMembers().isEmpty());
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertTrue(dr.getOfflineAndEqualMembers().isEmpty());
    dr.forceIFCompaction();
    assertEquals(null, dr.getMyInitializingID());
    assertEquals(myId, dr.getMyPersistentID());
    assertTrue(dr.getOnlineMembers().isEmpty());
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertTrue(dr.getOfflineAndEqualMembers().isEmpty());
    // do recovery
    close(lr);
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertEquals(null, dr.getMyInitializingID());
    assertEquals(myId, dr.getMyPersistentID());
    assertTrue(dr.getOnlineMembers().isEmpty());
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertTrue(dr.getOfflineAndEqualMembers().isEmpty());
}
Also used : PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

PersistentMemberID (org.apache.geode.internal.cache.persistence.PersistentMemberID)35 Test (org.junit.Test)14 HashSet (java.util.HashSet)10 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)8 Set (java.util.Set)7 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)7 HashMap (java.util.HashMap)6 UnitTest (org.apache.geode.test.junit.categories.UnitTest)6 PersistentMemberPattern (org.apache.geode.internal.cache.persistence.PersistentMemberPattern)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 PersistentMemberManager (org.apache.geode.internal.cache.persistence.PersistentMemberManager)4 File (java.io.File)3 DiskAccessException (org.apache.geode.cache.DiskAccessException)3 DiskStoreID (org.apache.geode.internal.cache.persistence.DiskStoreID)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 Entry (java.util.Map.Entry)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CancelException (org.apache.geode.CancelException)2