Search in sources :

Example 76 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class DescribeDiskStoreFunctionJUnitTest method setupCacheServersForTestExecute.

private Set<DiskStoreDetails.CacheServerDetails> setupCacheServersForTestExecute(final InternalCache mockCache, final String diskStoreName) {
    final CacheServer mockCacheServer1 = mockContext.mock(CacheServer.class, "CacheServer1");
    final CacheServer mockCacheServer2 = mockContext.mock(CacheServer.class, "CacheServer2");
    final CacheServer mockCacheServer3 = mockContext.mock(CacheServer.class, "CacheServer3");
    final ClientSubscriptionConfig cacheServer1ClientSubscriptionConfig = mockContext.mock(ClientSubscriptionConfig.class, "cacheServer1ClientSubscriptionConfig");
    final ClientSubscriptionConfig cacheServer3ClientSubscriptionConfig = mockContext.mock(ClientSubscriptionConfig.class, "cacheServer3ClientSubscriptionConfig");
    mockContext.checking(new Expectations() {

        {
            oneOf(mockCache).getCacheServers();
            will(returnValue(Arrays.asList(mockCacheServer1, mockCacheServer2, mockCacheServer3)));
            exactly(2).of(mockCacheServer1).getClientSubscriptionConfig();
            will(returnValue(cacheServer1ClientSubscriptionConfig));
            oneOf(cacheServer1ClientSubscriptionConfig).getDiskStoreName();
            will(returnValue(diskStoreName));
            oneOf(mockCacheServer2).getClientSubscriptionConfig();
            will(returnValue(null));
            exactly(2).of(mockCacheServer3).getClientSubscriptionConfig();
            will(returnValue(cacheServer3ClientSubscriptionConfig));
            oneOf(cacheServer3ClientSubscriptionConfig).getDiskStoreName();
            will(returnValue(""));
            oneOf(mockCacheServer1).getBindAddress();
            will(returnValue("10.127.0.1"));
            oneOf(mockCacheServer1).getPort();
            will(returnValue(10123));
            oneOf(mockCacheServer1).getHostnameForClients();
            will(returnValue("rodan"));
        }
    });
    return CollectionUtils.asSet(createCacheServerDetails("10.127.0.1", 10123, "rodan"));
}
Also used : Expectations(org.jmock.Expectations) ClientSubscriptionConfig(org.apache.geode.cache.server.ClientSubscriptionConfig) CacheServer(org.apache.geode.cache.server.CacheServer)

Example 77 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class DescribeDiskStoreFunctionJUnitTest method testSetCacheServerDetails.

@Test
public void testSetCacheServerDetails() {
    final String diskStoreName = "testDiskStore";
    final InternalCache mockCache = mockContext.mock(InternalCache.class, "Cache");
    final CacheServer mockCacheServer1 = mockContext.mock(CacheServer.class, "CacheServer1");
    final CacheServer mockCacheServer2 = mockContext.mock(CacheServer.class, "CacheServer2");
    final CacheServer mockCacheServer3 = mockContext.mock(CacheServer.class, "CacheServer3");
    final ClientSubscriptionConfig mockCacheServer1ClientSubscriptionConfig = mockContext.mock(ClientSubscriptionConfig.class, "cacheServer1ClientSubscriptionConfig");
    final ClientSubscriptionConfig mockCacheServer2ClientSubscriptionConfig = mockContext.mock(ClientSubscriptionConfig.class, "cacheServer2ClientSubscriptionConfig");
    final DiskStore mockDiskStore = mockContext.mock(DiskStore.class, "DiskStore");
    mockContext.checking(new Expectations() {

        {
            oneOf(mockCache).getCacheServers();
            will(returnValue(Arrays.asList(mockCacheServer1, mockCacheServer2, mockCacheServer3)));
            exactly(2).of(mockCacheServer1).getClientSubscriptionConfig();
            will(returnValue(mockCacheServer1ClientSubscriptionConfig));
            oneOf(mockCacheServer1ClientSubscriptionConfig).getDiskStoreName();
            will(returnValue(diskStoreName));
            oneOf(mockCacheServer1).getBindAddress();
            will(returnValue("10.127.255.1"));
            oneOf(mockCacheServer1).getPort();
            will(returnValue(65536));
            oneOf(mockCacheServer1).getHostnameForClients();
            will(returnValue("gemini"));
            exactly(2).of(mockCacheServer2).getClientSubscriptionConfig();
            will(returnValue(mockCacheServer2ClientSubscriptionConfig));
            oneOf(mockCacheServer2ClientSubscriptionConfig).getDiskStoreName();
            will(returnValue("  "));
            oneOf(mockCacheServer3).getClientSubscriptionConfig();
            will(returnValue(null));
            exactly(3).of(mockDiskStore).getName();
            will(returnValue(diskStoreName));
        }
    });
    final Set<DiskStoreDetails.CacheServerDetails> expectedCacheServerDetails = CollectionUtils.asSet(createCacheServerDetails("10.127.255.1", 65536, "gemini"));
    final DiskStoreDetails diskStoreDetails = new DiskStoreDetails(diskStoreName, "memberOne");
    final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null);
    function.setCacheServerDetails(mockCache, mockDiskStore, diskStoreDetails);
    assertCacheServerDetails(expectedCacheServerDetails, diskStoreDetails);
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) Expectations(org.jmock.Expectations) ClientSubscriptionConfig(org.apache.geode.cache.server.ClientSubscriptionConfig) DiskStoreDetails(org.apache.geode.management.internal.cli.domain.DiskStoreDetails) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServer(org.apache.geode.cache.server.CacheServer) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 78 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class DescribeDiskStoreFunctionJUnitTest method testIsCacheServerUsingDiskStoreWhenUsingDefaultDiskStore.

@Test
public void testIsCacheServerUsingDiskStoreWhenUsingDefaultDiskStore() {
    final CacheServer mockCacheServer = mockContext.mock(CacheServer.class, "CacheServer");
    final ClientSubscriptionConfig mockClientSubscriptionConfig = mockContext.mock(ClientSubscriptionConfig.class, "ClientSubscriptionConfig");
    final DiskStore mockDiskStore = mockContext.mock(DiskStore.class, "DiskStore");
    mockContext.checking(new Expectations() {

        {
            exactly(2).of(mockCacheServer).getClientSubscriptionConfig();
            will(returnValue(mockClientSubscriptionConfig));
            oneOf(mockClientSubscriptionConfig).getDiskStoreName();
            will(returnValue(""));
            oneOf(mockDiskStore).getName();
            will(returnValue(DiskStoreDetails.DEFAULT_DISK_STORE_NAME));
        }
    });
    final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null);
    assertTrue(function.isUsingDiskStore(mockCacheServer, mockDiskStore));
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) Expectations(org.jmock.Expectations) ClientSubscriptionConfig(org.apache.geode.cache.server.ClientSubscriptionConfig) CacheServer(org.apache.geode.cache.server.CacheServer) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 79 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class DescribeDiskStoreFunctionJUnitTest method testIsCacheServerUsingDiskStore.

@Test
public void testIsCacheServerUsingDiskStore() {
    final String diskStoreName = "testDiskStore";
    final CacheServer mockCacheServer = mockContext.mock(CacheServer.class, "CacheServer");
    final ClientSubscriptionConfig mockClientSubscriptionConfig = mockContext.mock(ClientSubscriptionConfig.class, "ClientSubscriptionConfig");
    final DiskStore mockDiskStore = mockContext.mock(DiskStore.class, "DiskStore");
    mockContext.checking(new Expectations() {

        {
            exactly(2).of(mockCacheServer).getClientSubscriptionConfig();
            will(returnValue(mockClientSubscriptionConfig));
            oneOf(mockClientSubscriptionConfig).getDiskStoreName();
            will(returnValue(diskStoreName));
            oneOf(mockDiskStore).getName();
            will(returnValue(diskStoreName));
        }
    });
    final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null);
    assertTrue(function.isUsingDiskStore(mockCacheServer, mockDiskStore));
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) Expectations(org.jmock.Expectations) ClientSubscriptionConfig(org.apache.geode.cache.server.ClientSubscriptionConfig) CacheServer(org.apache.geode.cache.server.CacheServer) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 80 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class ShowMetricsDUnitTest method testShowMetricsMember.

// GEODE-1764
@Category(FlakyTest.class)
@Test
public void testShowMetricsMember() throws ClassNotFoundException, IOException, InterruptedException {
    systemSetUp();
    Cache cache = getCache();
    final DistributedMember distributedMember = cache.getDistributedSystem().getDistributedMember();
    final String exportFileName = "memberMetricReport.csv";
    int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(1);
    CacheServer cs = getCache().addCacheServer();
    cs.setPort(ports[0]);
    cs.start();
    final int cacheServerPort = cs.getPort();
    SerializableCallable showMetricCmd = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            WaitCriterion wc = createMBeanWaitCriterion(3, "", distributedMember, 0);
            waitForCriterion(wc, 5000, 500, true);
            wc = createMBeanWaitCriterion(5, "", distributedMember, cacheServerPort);
            waitForCriterion(wc, 10000, 500, true);
            final String command = CliStrings.SHOW_METRICS + " --" + CliStrings.SHOW_METRICS__MEMBER + "=" + distributedMember.getId() + " --" + CliStrings.SHOW_METRICS__CACHESERVER__PORT + "=" + cacheServerPort + " --" + CliStrings.SHOW_METRICS__FILE + "=" + exportFileName;
            CommandProcessor commandProcessor = new CommandProcessor();
            Result result = commandProcessor.createCommandStatement(command, Collections.EMPTY_MAP).process();
            String resultAsString = commandResultToString((CommandResult) result);
            assertEquals(resultAsString, true, result.getStatus().equals(Status.OK));
            assertTrue(result.hasIncomingFiles());
            result.saveIncomingFiles(null);
            File file = new File(exportFileName);
            file.deleteOnExit();
            assertTrue(file.exists());
            file.delete();
            return resultAsString;
        }
    };
    // Invoke the command in the Manager VM
    final VM managerVm = Host.getHost(0).getVM(0);
    Object managerResultObj = managerVm.invoke(showMetricCmd);
    String managerResult = (String) managerResultObj;
    getLogWriter().info("#SB Manager");
    getLogWriter().info(managerResult);
    cs.stop();
}
Also used : Result(org.apache.geode.management.cli.Result) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedMember(org.apache.geode.distributed.DistributedMember) CacheServer(org.apache.geode.cache.server.CacheServer) CommandProcessor(org.apache.geode.management.internal.cli.remote.CommandProcessor) File(java.io.File) Cache(org.apache.geode.cache.Cache) 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)

Aggregations

CacheServer (org.apache.geode.cache.server.CacheServer)323 AttributesFactory (org.apache.geode.cache.AttributesFactory)99 Properties (java.util.Properties)97 Test (org.junit.Test)77 Cache (org.apache.geode.cache.Cache)76 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)76 RegionAttributes (org.apache.geode.cache.RegionAttributes)60 IOException (java.io.IOException)53 ClientCache (org.apache.geode.cache.client.ClientCache)53 Region (org.apache.geode.cache.Region)50 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)49 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)33 Iterator (java.util.Iterator)31 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)31 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)30 Host (org.apache.geode.test.dunit.Host)27 VM (org.apache.geode.test.dunit.VM)25 DistributedSystem (org.apache.geode.distributed.DistributedSystem)20 CacheException (org.apache.geode.cache.CacheException)17 CacheFactory (org.apache.geode.cache.CacheFactory)17