Search in sources :

Example 1 with DiskStoreDetails

use of org.apache.geode.management.internal.cli.domain.DiskStoreDetails in project geode by apache.

the class DescribeDiskStoreFunctionJUnitTest method testExecute.

@Test
public void testExecute() throws Throwable {
    final UUID diskStoreId = UUID.randomUUID();
    final String diskStoreName = "mockDiskStore";
    final String memberId = "mockMemberId";
    final String memberName = "mockMemberName";
    final InternalCache mockCache = mockContext.mock(InternalCache.class, "Cache");
    final InternalDistributedMember mockMember = mockContext.mock(InternalDistributedMember.class, "DistributedMember");
    final DiskStore mockDiskStore = createMockDiskStore(diskStoreId, diskStoreName, true, false, 75, 8192l, 500, 120l, 10240, createFileArray("/export/disk/backup", "/export/disk/overflow", "/export/disk/persistence"), createIntArray(10240, 204800, 4096000), 50, 75);
    final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "testExecute$FunctionContext");
    final TestResultSender testResultSender = new TestResultSender();
    mockContext.checking(new Expectations() {

        {
            oneOf(mockCache).getMyId();
            will(returnValue(mockMember));
            oneOf(mockCache).findDiskStore(diskStoreName);
            will(returnValue(mockDiskStore));
            oneOf(mockCache).getPdxPersistent();
            will(returnValue(true));
            oneOf(mockCache).getPdxDiskStore();
            will(returnValue("memoryStore"));
            oneOf(mockMember).getId();
            will(returnValue(memberId));
            oneOf(mockMember).getName();
            will(returnValue(memberName));
            oneOf(mockFunctionContext).getArguments();
            will(returnValue(diskStoreName));
            oneOf(mockFunctionContext).getResultSender();
            will(returnValue(testResultSender));
        }
    });
    final Set<DiskStoreDetails.RegionDetails> expectedRegionDetails = setupRegionsForTestExecute(mockCache, diskStoreName);
    final Set<DiskStoreDetails.GatewayDetails> expectedGatewayDetails = setupGatewaysForTestExecute(mockCache, diskStoreName);
    final Set<DiskStoreDetails.CacheServerDetails> expectedCacheServerDetails = setupCacheServersForTestExecute(mockCache, diskStoreName);
    final Set<DiskStoreDetails.AsyncEventQueueDetails> expectedAsyncEventQueueDetails = setupAsyncEventQueuesForTestExecute(mockCache, diskStoreName);
    final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache);
    function.execute(mockFunctionContext);
    final List<?> results = testResultSender.getResults();
    assertNotNull(results);
    assertEquals(1, results.size());
    final DiskStoreDetails diskStoreDetails = (DiskStoreDetails) results.get(0);
    assertNotNull(diskStoreDetails);
    assertEquals(diskStoreId, diskStoreDetails.getId());
    assertEquals(diskStoreName, diskStoreDetails.getName());
    assertEquals(memberId, diskStoreDetails.getMemberId());
    assertEquals(memberName, diskStoreDetails.getMemberName());
    assertTrue(diskStoreDetails.getAllowForceCompaction());
    assertFalse(diskStoreDetails.getAutoCompact());
    assertEquals(75, diskStoreDetails.getCompactionThreshold().intValue());
    assertEquals(8192l, diskStoreDetails.getMaxOplogSize().longValue());
    assertFalse(diskStoreDetails.isPdxSerializationMetaDataStored());
    assertEquals(500, diskStoreDetails.getQueueSize().intValue());
    assertEquals(120l, diskStoreDetails.getTimeInterval().longValue());
    assertEquals(10240, diskStoreDetails.getWriteBufferSize().intValue());
    assertEquals(50.0f, diskStoreDetails.getDiskUsageWarningPercentage().floatValue(), 0.0f);
    assertEquals(75.0f, diskStoreDetails.getDiskUsageCriticalPercentage().floatValue(), 0.0f);
    final List<String> expectedDiskDirs = Arrays.asList(new File("/export/disk/backup").getAbsolutePath(), new File("/export/disk/overflow").getAbsolutePath(), new File("/export/disk/persistence").getAbsolutePath());
    final List<Integer> expectdDiskDirSizes = Arrays.asList(10240, 204800, 4096000);
    int count = 0;
    for (final DiskStoreDetails.DiskDirDetails diskDirDetails : diskStoreDetails) {
        assertTrue(expectedDiskDirs.contains(diskDirDetails.getAbsolutePath()));
        assertTrue(expectdDiskDirSizes.contains(diskDirDetails.getSize()));
        count++;
    }
    assertEquals(expectedDiskDirs.size(), count);
    assertRegionDetails(expectedRegionDetails, diskStoreDetails);
    assertCacheServerDetails(expectedCacheServerDetails, diskStoreDetails);
    assertGatewayDetails(expectedGatewayDetails, diskStoreDetails);
    assertAsyncEventQueueDetails(expectedAsyncEventQueueDetails, diskStoreDetails);
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) UUID(java.util.UUID) Expectations(org.jmock.Expectations) DiskStoreDetails(org.apache.geode.management.internal.cli.domain.DiskStoreDetails) FunctionContext(org.apache.geode.cache.execute.FunctionContext) DiskStore(org.apache.geode.cache.DiskStore) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) File(java.io.File) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 2 with DiskStoreDetails

use of org.apache.geode.management.internal.cli.domain.DiskStoreDetails 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 3 with DiskStoreDetails

use of org.apache.geode.management.internal.cli.domain.DiskStoreDetails in project geode by apache.

the class ListDiskStoresFunctionJUnitTest method testExecuteOnMemberHavingNoDiskStores.

@Test
@SuppressWarnings("unchecked")
public void testExecuteOnMemberHavingNoDiskStores() throws Throwable {
    final InternalCache mockCache = mockContext.mock(InternalCache.class, "Cache");
    final InternalDistributedMember mockMember = mockContext.mock(InternalDistributedMember.class, "DistributedMember");
    final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "FunctionContext");
    final TestResultSender testResultSender = new TestResultSender();
    mockContext.checking(new Expectations() {

        {
            oneOf(mockCache).getMyId();
            will(returnValue(mockMember));
            oneOf(mockCache).listDiskStoresIncludingRegionOwned();
            will(returnValue(Collections.emptyList()));
            oneOf(mockFunctionContext).getResultSender();
            will(returnValue(testResultSender));
        }
    });
    final ListDiskStoresFunction function = createListDiskStoresFunction(mockCache);
    function.execute(mockFunctionContext);
    final List<?> results = testResultSender.getResults();
    assertNotNull(results);
    assertEquals(1, results.size());
    final Set<DiskStoreDetails> diskStoreDetails = (Set<DiskStoreDetails>) results.get(0);
    assertNotNull(diskStoreDetails);
    assertTrue(diskStoreDetails.isEmpty());
}
Also used : Expectations(org.jmock.Expectations) Set(java.util.Set) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DiskStoreDetails(org.apache.geode.management.internal.cli.domain.DiskStoreDetails) InternalCache(org.apache.geode.internal.cache.InternalCache) FunctionContext(org.apache.geode.cache.execute.FunctionContext) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 4 with DiskStoreDetails

use of org.apache.geode.management.internal.cli.domain.DiskStoreDetails in project geode by apache.

the class ListDiskStoresFunctionJUnitTest method testExecute.

@Test
@SuppressWarnings("unchecked")
public void testExecute() throws Throwable {
    final UUID mockDiskStoreOneId = UUID.randomUUID();
    final UUID mockDiskStoreTwoId = UUID.randomUUID();
    final UUID mockDiskStoreThreeId = UUID.randomUUID();
    final String memberId = "mockMemberId";
    final String memberName = "mockMemberName";
    final InternalCache mockCache = mockContext.mock(InternalCache.class, "Cache");
    final InternalDistributedMember mockMember = mockContext.mock(InternalDistributedMember.class, "DistributedMember");
    final DiskStoreImpl mockDiskStoreOne = mockContext.mock(DiskStoreImpl.class, "DiskStoreOne");
    final DiskStoreImpl mockDiskStoreTwo = mockContext.mock(DiskStoreImpl.class, "DiskStoreTwo");
    final DiskStoreImpl mockDiskStoreThree = mockContext.mock(DiskStoreImpl.class, "DiskStoreThree");
    final Collection<DiskStoreImpl> mockDiskStores = new ArrayList<DiskStoreImpl>();
    mockDiskStores.add(mockDiskStoreOne);
    mockDiskStores.add(mockDiskStoreTwo);
    mockDiskStores.add(mockDiskStoreThree);
    final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "FunctionContext");
    final TestResultSender testResultSender = new TestResultSender();
    mockContext.checking(new Expectations() {

        {
            oneOf(mockCache).getMyId();
            will(returnValue(mockMember));
            oneOf(mockCache).listDiskStoresIncludingRegionOwned();
            will(returnValue(mockDiskStores));
            exactly(3).of(mockMember).getId();
            will(returnValue(memberId));
            exactly(3).of(mockMember).getName();
            will(returnValue(memberName));
            oneOf(mockDiskStoreOne).getDiskStoreUUID();
            will(returnValue(mockDiskStoreOneId));
            oneOf(mockDiskStoreOne).getName();
            will(returnValue("ds-backup"));
            oneOf(mockDiskStoreTwo).getDiskStoreUUID();
            will(returnValue(mockDiskStoreTwoId));
            oneOf(mockDiskStoreTwo).getName();
            will(returnValue("ds-overflow"));
            oneOf(mockDiskStoreThree).getDiskStoreUUID();
            will(returnValue(mockDiskStoreThreeId));
            oneOf(mockDiskStoreThree).getName();
            will(returnValue("ds-persistence"));
            oneOf(mockFunctionContext).getResultSender();
            will(returnValue(testResultSender));
        }
    });
    final ListDiskStoresFunction function = createListDiskStoresFunction(mockCache);
    function.execute(mockFunctionContext);
    final List<?> results = testResultSender.getResults();
    assertNotNull(results);
    assertEquals(1, results.size());
    final Set<DiskStoreDetails> diskStoreDetails = (Set<DiskStoreDetails>) results.get(0);
    assertNotNull(diskStoreDetails);
    assertEquals(3, diskStoreDetails.size());
    diskStoreDetails.containsAll(Arrays.asList(createDiskStoreDetails(mockDiskStoreOneId, "ds-backup", memberId, memberName), createDiskStoreDetails(mockDiskStoreTwoId, "ds-overflow", memberId, memberName), createDiskStoreDetails(mockDiskStoreThreeId, "ds-persistence", memberId, memberName)));
}
Also used : Expectations(org.jmock.Expectations) Set(java.util.Set) ArrayList(java.util.ArrayList) DiskStoreDetails(org.apache.geode.management.internal.cli.domain.DiskStoreDetails) InternalCache(org.apache.geode.internal.cache.InternalCache) FunctionContext(org.apache.geode.cache.execute.FunctionContext) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DiskStoreImpl(org.apache.geode.internal.cache.DiskStoreImpl) UUID(java.util.UUID) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 5 with DiskStoreDetails

use of org.apache.geode.management.internal.cli.domain.DiskStoreDetails in project geode by apache.

the class ListDiskStoresFunctionJUnitTest method testExecuteOnMemberWithANonGemFireCache.

@Test
@SuppressWarnings("unchecked")
public void testExecuteOnMemberWithANonGemFireCache() throws Throwable {
    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
    final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "FunctionContext");
    final TestResultSender testResultSender = new TestResultSender();
    mockContext.checking(new Expectations() {

        {
            oneOf(mockFunctionContext).getResultSender();
            will(returnValue(testResultSender));
        }
    });
    final ListDiskStoresFunction function = createListDiskStoresFunction(mockCache);
    function.execute(mockFunctionContext);
    final List<?> results = testResultSender.getResults();
    assertNotNull(results);
    assertEquals(1, results.size());
    final Set<DiskStoreDetails> diskStoreDetails = (Set<DiskStoreDetails>) results.get(0);
    assertNotNull(diskStoreDetails);
    assertTrue(diskStoreDetails.isEmpty());
}
Also used : Expectations(org.jmock.Expectations) Set(java.util.Set) DiskStoreDetails(org.apache.geode.management.internal.cli.domain.DiskStoreDetails) FunctionContext(org.apache.geode.cache.execute.FunctionContext) InternalCache(org.apache.geode.internal.cache.InternalCache) Cache(org.apache.geode.cache.Cache) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

DiskStoreDetails (org.apache.geode.management.internal.cli.domain.DiskStoreDetails)21 InternalCache (org.apache.geode.internal.cache.InternalCache)15 UnitTest (org.apache.geode.test.junit.categories.UnitTest)13 Expectations (org.jmock.Expectations)13 Test (org.junit.Test)13 DiskStore (org.apache.geode.cache.DiskStore)9 DistributedMember (org.apache.geode.distributed.DistributedMember)6 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 FunctionContext (org.apache.geode.cache.execute.FunctionContext)4 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)4 AbstractExecution (org.apache.geode.internal.cache.execute.AbstractExecution)4 Cache (org.apache.geode.cache.Cache)3 ResultCollector (org.apache.geode.cache.execute.ResultCollector)3 ListDiskStoresFunction (org.apache.geode.management.internal.cli.functions.ListDiskStoresFunction)3 HashSet (java.util.HashSet)2 List (java.util.List)2 UUID (java.util.UUID)2 Execution (org.apache.geode.cache.execute.Execution)2 CacheServer (org.apache.geode.cache.server.CacheServer)2