Search in sources :

Example 1 with FunctionContext

use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.

the class LuceneSearchIndexFunctionJUnitTest method testExecute.

@Test
@SuppressWarnings("unchecked")
public void testExecute() throws LuceneQueryException {
    FunctionContext context = mock(FunctionContext.class);
    ResultSender resultSender = mock(ResultSender.class);
    GemFireCacheImpl cache = Fakes.cache();
    LuceneQueryInfo queryInfo = createMockQueryInfo("index", "region", "field1:region1", "field1", 1);
    InternalLuceneService service = getMockLuceneService("A", "Value", "1.2");
    Region mockRegion = mock(Region.class);
    LuceneSearchIndexFunction function = spy(LuceneSearchIndexFunction.class);
    doReturn(queryInfo).when(context).getArguments();
    doReturn(resultSender).when(context).getResultSender();
    doReturn(cache).when(function).getCache();
    when(cache.getService(eq(InternalLuceneService.class))).thenReturn(service);
    when(cache.getRegion(queryInfo.getRegionPath())).thenReturn(mockRegion);
    function.execute(context);
    ArgumentCaptor<Set> resultCaptor = ArgumentCaptor.forClass(Set.class);
    verify(resultSender).lastResult(resultCaptor.capture());
    Set<LuceneSearchResults> result = resultCaptor.getValue();
    assertEquals(1, result.size());
    for (LuceneSearchResults searchResult : result) {
        assertEquals("A", searchResult.getKey());
        assertEquals("Value", searchResult.getValue());
        assertEquals(1.2, searchResult.getScore(), .1);
    }
}
Also used : Set(java.util.Set) LuceneSearchResults(org.apache.geode.cache.lucene.internal.cli.LuceneSearchResults) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Region(org.apache.geode.cache.Region) InternalLuceneService(org.apache.geode.cache.lucene.internal.InternalLuceneService) FunctionContext(org.apache.geode.cache.execute.FunctionContext) ResultSender(org.apache.geode.cache.execute.ResultSender) LuceneQueryInfo(org.apache.geode.cache.lucene.internal.cli.LuceneQueryInfo) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 2 with FunctionContext

use of org.apache.geode.cache.execute.FunctionContext 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 3 with FunctionContext

use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.

the class DescribeDiskStoreFunctionJUnitTest method testExecuteOnMemberHavingANonGemFireCache.

@Test
public void testExecuteOnMemberHavingANonGemFireCache() 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() {

        {
            exactly(0).of(mockFunctionContext).getResultSender();
            will(returnValue(testResultSender));
        }
    });
    final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache);
    function.execute(mockFunctionContext);
    final List<?> results = testResultSender.getResults();
    assertNotNull(results);
    assertTrue(results.isEmpty());
}
Also used : Expectations(org.jmock.Expectations) 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)

Example 4 with FunctionContext

use of org.apache.geode.cache.execute.FunctionContext 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 5 with FunctionContext

use of org.apache.geode.cache.execute.FunctionContext 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)

Aggregations

FunctionContext (org.apache.geode.cache.execute.FunctionContext)68 FunctionAdapter (org.apache.geode.cache.execute.FunctionAdapter)38 Test (org.junit.Test)35 HashSet (java.util.HashSet)30 RegionFunctionContext (org.apache.geode.cache.execute.RegionFunctionContext)30 ArrayList (java.util.ArrayList)29 FunctionException (org.apache.geode.cache.execute.FunctionException)28 ResultCollector (org.apache.geode.cache.execute.ResultCollector)28 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)28 Region (org.apache.geode.cache.Region)27 Execution (org.apache.geode.cache.execute.Execution)26 IgnoredException (org.apache.geode.test.dunit.IgnoredException)24 List (java.util.List)20 Set (java.util.Set)19 Iterator (java.util.Iterator)16 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)15 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)15 UnitTest (org.apache.geode.test.junit.categories.UnitTest)15 DistributedMember (org.apache.geode.distributed.DistributedMember)14 InternalCache (org.apache.geode.internal.cache.InternalCache)14