Search in sources :

Example 56 with FixedPartitionAttributes

use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.

the class FixedPRSinglehopDUnitTest method createServer.

public static int createServer(boolean isAccessor, List<FixedPartitionAttributes> fpaList) {
    FixedPRSinglehopDUnitTest test = new FixedPRSinglehopDUnitTest();
    cache = test.getCache();
    CacheServer server = cache.addCacheServer();
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    server.setPort(port);
    server.setHostnameForClients("localhost");
    try {
        server.start();
    } catch (IOException e) {
        Assert.fail("Failed to start server ", e);
    }
    if (!fpaList.isEmpty() || isAccessor) {
        PartitionAttributesFactory paf = new PartitionAttributesFactory();
        paf.setRedundantCopies(1).setTotalNumBuckets(12);
        if (isAccessor) {
            paf.setLocalMaxMemory(0);
        }
        for (FixedPartitionAttributes fpa : fpaList) {
            paf.addFixedPartitionAttributes(fpa);
        }
        paf.setPartitionResolver(new SingleHopQuarterPartitionResolver());
        AttributesFactory attr = new AttributesFactory();
        attr.setPartitionAttributes(paf.create());
        region = cache.createRegion(PR_NAME, attr.create());
        assertNotNull(region);
        LogWriterUtils.getLogWriter().info("Partitioned Region " + PR_NAME + " created Successfully :" + region.toString());
    }
    return port;
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SingleHopQuarterPartitionResolver(org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver) CacheServer(org.apache.geode.cache.server.CacheServer) IOException(java.io.IOException)

Example 57 with FixedPartitionAttributes

use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.

the class FixedPRSinglehopDUnitTest method test_MetadataContents.

// 4 servers, 1 client connected to all 4 servers.
// Put data, get data and make the metadata stable.
// Now verify that metadata has all 8 buckets info.
// Now update and ensure the fetch service is never called.
// GEODE-1176: random ports, time sensitive, waitForCriterion
@Category(FlakyTest.class)
@Test
public void test_MetadataContents() {
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM server3 = host.getVM(2);
    VM server4 = host.getVM(3);
    List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
    fpaList.add(FixedPartitionAttributes.createFixedPartition("Q1", true, 3));
    fpaList.add(FixedPartitionAttributes.createFixedPartition("Q2", false, 3));
    Integer port1 = (Integer) server1.invoke(() -> FixedPRSinglehopDUnitTest.createServer(false, fpaList));
    fpaList.clear();
    fpaList.add(FixedPartitionAttributes.createFixedPartition("Q3", true, 3));
    fpaList.add(FixedPartitionAttributes.createFixedPartition("Q4", false, 3));
    Integer port2 = (Integer) server2.invoke(() -> FixedPRSinglehopDUnitTest.createServer(false, fpaList));
    fpaList.clear();
    fpaList.add(FixedPartitionAttributes.createFixedPartition("Q2", true, 3));
    fpaList.add(FixedPartitionAttributes.createFixedPartition("Q3", false, 3));
    Integer port3 = (Integer) server3.invoke(() -> FixedPRSinglehopDUnitTest.createServer(false, fpaList));
    fpaList.clear();
    fpaList.add(FixedPartitionAttributes.createFixedPartition("Q4", true, 3));
    fpaList.add(FixedPartitionAttributes.createFixedPartition("Q1", false, 3));
    Integer port4 = (Integer) server4.invoke(() -> FixedPRSinglehopDUnitTest.createServer(false, fpaList));
    createClient(port1, port2, port3, port4);
    putIntoPartitionedRegions();
    getFromPartitionedRegions();
    SerializableRunnableIF printView = () -> FixedPRSinglehopDUnitTest.printView();
    server1.invoke(printView);
    server2.invoke(printView);
    server3.invoke(printView);
    server4.invoke(printView);
    int totalBucketOnServer = 0;
    SerializableCallableIF<Integer> getBucketCount = () -> FixedPRSinglehopDUnitTest.primaryBucketsOnServer();
    totalBucketOnServer += server1.invoke(getBucketCount);
    totalBucketOnServer += server2.invoke(getBucketCount);
    totalBucketOnServer += server3.invoke(getBucketCount);
    totalBucketOnServer += server4.invoke(getBucketCount);
    verifyMetadata(totalBucketOnServer, 2);
    updateIntoSinglePR(true);
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) VM(org.apache.geode.test.dunit.VM) ArrayList(java.util.ArrayList) Host(org.apache.geode.test.dunit.Host) SerializableRunnableIF(org.apache.geode.test.dunit.SerializableRunnableIF) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 58 with FixedPartitionAttributes

use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.

the class FixedPRSinglehopDUnitTest method createPeer.

public static void createPeer(boolean isAccessor, List<FixedPartitionAttributes> fpaList) {
    FixedPRSinglehopDUnitTest test = new FixedPRSinglehopDUnitTest();
    cache = test.getCache();
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(1).setTotalNumBuckets(12);
    if (isAccessor) {
        paf.setLocalMaxMemory(0);
    }
    for (FixedPartitionAttributes fpa : fpaList) {
        paf.addFixedPartitionAttributes(fpa);
    }
    paf.setPartitionResolver(new SingleHopQuarterPartitionResolver());
    AttributesFactory attr = new AttributesFactory();
    attr.setPartitionAttributes(paf.create());
    region = cache.createRegion(PR_NAME, attr.create());
    assertNotNull(region);
    LogWriterUtils.getLogWriter().info("Partitioned Region " + PR_NAME + " created Successfully :" + region.toString());
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SingleHopQuarterPartitionResolver(org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver)

Example 59 with FixedPartitionAttributes

use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.

the class FixedPRSinglehopDUnitTest method testMetadataInClientWithFixedPartitions.

/**
   * This test will check to see if all the partitionAttributes are sent to the client. In case one
   * partition comes late, we should fetch that when there is a network hop because of that
   * partitioned region. This test will create 3 servers with partition. Do some operations on them.
   * Validate that the metadata are fetched and then later up one more partition and do some
   * operations on them. It should fetch new fpa. Verify that the correct servers are known to the
   * client metadata service at the end.
   */
@Test
public void testMetadataInClientWithFixedPartitions() throws Exception {
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM server3 = host.getVM(2);
    VM server4 = host.getVM(3);
    Boolean simpleFPR = false;
    final int portLocator = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    final String hostLocator = NetworkUtils.getServerHostName(server1.getHost());
    final String locator = hostLocator + "[" + portLocator + "]";
    server3.invoke(() -> FixedPRSinglehopDUnitTest.startLocatorInVM(portLocator));
    try {
        List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
        fpaList.add(FixedPartitionAttributes.createFixedPartition("Q1", true, 3));
        fpaList.add(FixedPartitionAttributes.createFixedPartition("Q2", false, 3));
        Integer port1 = (Integer) server1.invoke(() -> FixedPRSinglehopDUnitTest.createServerWithLocator(locator, false, fpaList, simpleFPR));
        fpaList.clear();
        fpaList.add(FixedPartitionAttributes.createFixedPartition("Q3", true, 3));
        Integer port2 = (Integer) server2.invoke(() -> FixedPRSinglehopDUnitTest.createServerWithLocator(locator, false, fpaList, simpleFPR));
        fpaList.clear();
        createClientWithLocator(hostLocator, portLocator);
        putIntoPartitionedRegionsThreeQs();
        getFromPartitionedRegionsFor3Qs();
        // Server 1 is actually primary for both Q1 and Q2, since there is no FPA server with
        // primary set to true.
        Awaitility.await().atMost(15, TimeUnit.SECONDS).until(() -> (server1.invoke(FixedPRSinglehopDUnitTest::primaryBucketsOnServer) == 6) && (server2.invoke(FixedPRSinglehopDUnitTest::primaryBucketsOnServer) == 3));
        // TODO: Verify that all the fpa's are in the map
        server1.invoke(FixedPRSinglehopDUnitTest::printView);
        server2.invoke(FixedPRSinglehopDUnitTest::printView);
        int totalBucketOnServer = 0;
        totalBucketOnServer += (Integer) server1.invoke(FixedPRSinglehopDUnitTest::primaryBucketsOnServer);
        totalBucketOnServer += (Integer) server2.invoke(FixedPRSinglehopDUnitTest::primaryBucketsOnServer);
        verifyMetadata(totalBucketOnServer, 1);
        updateIntoSinglePRFor3Qs();
        // now create one more partition
        fpaList.clear();
        fpaList.add(FixedPartitionAttributes.createFixedPartition("Q4", true, 3));
        fpaList.add(FixedPartitionAttributes.createFixedPartition("Q2", true, 3));
        fpaList.add(FixedPartitionAttributes.createFixedPartition("Q1", false, 3));
        fpaList.add(FixedPartitionAttributes.createFixedPartition("Q3", false, 3));
        Integer port4 = (Integer) server4.invoke(() -> FixedPRSinglehopDUnitTest.createServerWithLocator(locator, false, fpaList, simpleFPR));
        putIntoPartitionedRegions();
        // Wait to make sure that the buckets have actually moved.
        Awaitility.await().atMost(15, TimeUnit.SECONDS).until(() -> (server1.invoke(FixedPRSinglehopDUnitTest::primaryBucketsOnServer) == 3) && (server2.invoke(FixedPRSinglehopDUnitTest::primaryBucketsOnServer) == 3) && (server4.invoke(FixedPRSinglehopDUnitTest::primaryBucketsOnServer) == 6));
        getFromPartitionedRegions();
        server1.invoke(FixedPRSinglehopDUnitTest::printView);
        server2.invoke(FixedPRSinglehopDUnitTest::printView);
        server4.invoke(FixedPRSinglehopDUnitTest::printView);
        updateIntoSinglePR(false);
        ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
        ClientPartitionAdvisor advisor = cms.getClientPartitionAdvisor("/" + PR_NAME);
        int[] expected = new int[] { port1, port1, port1, port4, port4, port4, port2, port2, port2, port4, port4, port4 };
        for (int i = 0; i < expected.length; i++) {
            ServerLocation primary = advisor.advisePrimaryServerLocation(i);
            assertNotNull("bucket " + i + " had no primary server", primary);
            assertEquals("bucket " + i + " was incorrect", expected[i], primary.getPort());
        }
    } finally {
        server3.invoke(FixedPRSinglehopDUnitTest::stopLocator);
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) ArrayList(java.util.ArrayList) Host(org.apache.geode.test.dunit.Host) VM(org.apache.geode.test.dunit.VM) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 60 with FixedPartitionAttributes

use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.

the class FixedPartitioningWithColocationAndPersistenceDUnitTest method testColocation_FPR_Persistence_ChildUsingAttributesOfParent.

@Test
public void testColocation_FPR_Persistence_ChildUsingAttributesOfParent() {
    try {
        member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        member3.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        member4.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("10", true, 5);
        FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition("30", false, 5);
        FixedPartitionAttributes fpa3 = FixedPartitionAttributes.createFixedPartition("40", false, 5);
        List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
        fpaList.add(fpa3);
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 2, 50, 20, new CustomerFixedPartitionResolver(), null, true));
        fpa1 = FixedPartitionAttributes.createFixedPartition("20", true, 5);
        fpa2 = FixedPartitionAttributes.createFixedPartition("30", false, 5);
        fpa3 = FixedPartitionAttributes.createFixedPartition("40", false, 5);
        fpaList.clear();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
        fpaList.add(fpa3);
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 2, 50, 20, new CustomerFixedPartitionResolver(), null, true));
        fpa1 = FixedPartitionAttributes.createFixedPartition("30", true, 5);
        fpa2 = FixedPartitionAttributes.createFixedPartition("10", false, 5);
        fpa3 = FixedPartitionAttributes.createFixedPartition("20", false, 5);
        fpaList.clear();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
        fpaList.add(fpa3);
        member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 2, 50, 20, new CustomerFixedPartitionResolver(), null, true));
        fpa1 = FixedPartitionAttributes.createFixedPartition("40", true, 5);
        fpa2 = FixedPartitionAttributes.createFixedPartition("10", false, 5);
        fpa3 = FixedPartitionAttributes.createFixedPartition("20", false, 5);
        fpaList.clear();
        fpaList.add(fpa1);
        fpaList.add(fpa2);
        fpaList.add(fpa3);
        member4.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 2, 50, 20, new CustomerFixedPartitionResolver(), null, true));
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
        member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
        member4.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
        member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
        member4.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
        member1.invoke(() -> FixedPartitioningTestBase.checkFPR("Order"));
        member1.invoke(() -> FixedPartitioningTestBase.checkFPR("Shipment"));
        member2.invoke(() -> FixedPartitioningTestBase.checkFPR("Order"));
        member2.invoke(() -> FixedPartitioningTestBase.checkFPR("Shipment"));
        member3.invoke(() -> FixedPartitioningTestBase.checkFPR("Order"));
        member3.invoke(() -> FixedPartitioningTestBase.checkFPR("Shipment"));
        member4.invoke(() -> FixedPartitioningTestBase.checkFPR("Order"));
        member4.invoke(() -> FixedPartitioningTestBase.checkFPR("Shipment"));
        member1.invoke(() -> FixedPartitioningTestBase.putOrderPartitionedRegion("Order"));
        member1.invoke(() -> FixedPartitioningTestBase.putCustomerPartitionedRegion("Customer"));
        member1.invoke(() -> FixedPartitioningTestBase.putShipmentPartitionedRegion("Shipment"));
        member1.invoke(() -> FixedPartitioningTestBase.validateAfterPutPartitionedRegion("Customer", "Order", "Shipment"));
        member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
        member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
        member3.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
        member4.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
    } catch (Exception e) {
        Assert.fail("Unexpected Exception ", e);
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ArrayList(java.util.ArrayList) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)63 Test (org.junit.Test)46 ArrayList (java.util.ArrayList)45 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)43 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)30 IgnoredException (org.apache.geode.test.dunit.IgnoredException)16 DuplicatePrimaryPartitionException (org.apache.geode.cache.DuplicatePrimaryPartitionException)15 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)15 PartitionNotAvailableException (org.apache.geode.cache.partition.PartitionNotAvailableException)15 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)12 AttributesFactory (org.apache.geode.cache.AttributesFactory)7 Region (org.apache.geode.cache.Region)6 VM (org.apache.geode.test.dunit.VM)6 Cache (org.apache.geode.cache.Cache)5 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)5 SingleHopQuarterPartitionResolver (org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver)5 Host (org.apache.geode.test.dunit.Host)5 IOException (java.io.IOException)4 QuarterPartitionResolver (org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver)4 HashSet (java.util.HashSet)3