Search in sources :

Example 36 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class DiskStoreCommandsJUnitTest method testGetDiskStoreListThrowsRuntimeException.

@Test(expected = RuntimeException.class)
public void testGetDiskStoreListThrowsRuntimeException() {
    final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
    final DistributedMember mockDistributedMember = mockContext.mock(DistributedMember.class, "DistributedMember");
    final Execution mockFunctionExecutor = mockContext.mock(Execution.class, "Function Executor");
    mockContext.checking(new Expectations() {

        {
            oneOf(mockFunctionExecutor).execute(with(aNonNull(ListDiskStoresFunction.class)));
            will(throwException(new RuntimeException("expected")));
        }
    });
    final DiskStoreCommands commands = createDiskStoreCommands(mockCache, mockDistributedMember, mockFunctionExecutor);
    try {
        commands.getDiskStoreListing(commands.getNormalMembers(mockCache));
    } catch (RuntimeException expected) {
        assertEquals("expected", expected.getMessage());
        throw expected;
    }
}
Also used : Expectations(org.jmock.Expectations) Execution(org.apache.geode.cache.execute.Execution) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) ListDiskStoresFunction(org.apache.geode.management.internal.cli.functions.ListDiskStoresFunction) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 37 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class DiskStoreCommandsJUnitTest method testGetDiskStoreListReturnsFunctionInvocationTargetExceptionInResults.

@Test
public void testGetDiskStoreListReturnsFunctionInvocationTargetExceptionInResults() {
    final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
    final DistributedMember mockDistributedMember = mockContext.mock(DistributedMember.class, "DistributedMember");
    final AbstractExecution mockFunctionExecutor = mockContext.mock(AbstractExecution.class, "Function Executor");
    final ResultCollector mockResultCollector = mockContext.mock(ResultCollector.class, "ResultCollector");
    final DiskStoreDetails diskStoreDetails = createDiskStoreDetails("memberOne", "cacheServerDiskStore");
    final List<DiskStoreDetails> expectedDiskStores = Arrays.asList(diskStoreDetails);
    final List<Object> results = new ArrayList<Object>();
    results.add(CollectionUtils.asSet(diskStoreDetails));
    results.add(new FunctionInvocationTargetException("expected"));
    mockContext.checking(new Expectations() {

        {
            oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true)));
            oneOf(mockFunctionExecutor).execute(with(aNonNull(ListDiskStoresFunction.class)));
            will(returnValue(mockResultCollector));
            oneOf(mockResultCollector).getResult();
            will(returnValue(results));
        }
    });
    final DiskStoreCommands commands = createDiskStoreCommands(mockCache, mockDistributedMember, mockFunctionExecutor);
    final List<DiskStoreDetails> actualDiskStores = commands.getDiskStoreListing(commands.getNormalMembers(mockCache));
    Assert.assertNotNull(actualDiskStores);
    assertEquals(expectedDiskStores, actualDiskStores);
}
Also used : Expectations(org.jmock.Expectations) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) ListDiskStoresFunction(org.apache.geode.management.internal.cli.functions.ListDiskStoresFunction) DiskStoreDetails(org.apache.geode.management.internal.cli.domain.DiskStoreDetails) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) DistributedMember(org.apache.geode.distributed.DistributedMember) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ResultCollector(org.apache.geode.cache.execute.ResultCollector) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 38 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class DiskStoreCommandsDUnitTest method testMissingDiskStore.

// GEODE-2102
@Category(FlakyTest.class)
@Test
public void testMissingDiskStore() {
    final String regionName = "testShowMissingDiskStoreRegion";
    setUpJmxManagerOnVm0ThenConnect(null);
    final VM vm0 = Host.getHost(0).getVM(0);
    final VM vm1 = Host.getHost(0).getVM(1);
    final String vm1Name = "VM" + vm1.getPid();
    final String diskStoreName = "DiskStoreCommandsDUnitTest";
    // Default setup creates a cache in the Manager, now create a cache in VM1
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            Properties localProps = new Properties();
            localProps.setProperty(NAME, vm1Name);
            getSystem(localProps);
            Cache cache = getCache();
        }
    });
    // Create a disk store and region in the Manager (VM0) and VM1 VMs
    for (final VM vm : (new VM[] { vm0, vm1 })) {
        final String vmName = "VM" + vm.getPid();
        vm.invoke(new SerializableRunnable() {

            public void run() {
                Cache cache = getCache();
                File diskStoreDirFile = new File(diskStoreName + vm.getPid());
                diskStoreDirFile.mkdirs();
                DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
                diskStoreFactory.setDiskDirs(new File[] { diskStoreDirFile });
                diskStoreFactory.setMaxOplogSize(1);
                diskStoreFactory.setAllowForceCompaction(true);
                diskStoreFactory.setAutoCompact(false);
                diskStoreFactory.create(regionName);
                RegionFactory regionFactory = cache.createRegionFactory();
                regionFactory.setDiskStoreName(regionName);
                regionFactory.setDiskSynchronous(true);
                regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
                regionFactory.setScope(Scope.DISTRIBUTED_ACK);
                regionFactory.create(regionName);
            }
        });
    }
    // Add data to the region
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(regionName);
            region.put("A", "B");
        }
    });
    // Make sure that everything thus far is okay and there are no missing disk stores
    CommandResult cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    assertTrue(commandResultToString(cmdResult).contains("No missing disk store found"));
    // Close the region in the Manager (VM0) VM
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(regionName);
            region.close();
        }
    });
    // Add data to VM1 and then close the region
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(regionName);
            region.put("A", "C");
            region.close();
        }
    });
    // Add the region back to the Manager (VM0) VM
    vm0.invokeAsync(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            RegionFactory regionFactory = cache.createRegionFactory();
            regionFactory.setDiskStoreName(regionName);
            regionFactory.setDiskSynchronous(true);
            regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
            regionFactory.setScope(Scope.DISTRIBUTED_ACK);
            try {
                regionFactory.create(regionName);
            } catch (DistributedSystemDisconnectedException ignore) {
            // okay to ignore
            }
        }
    });
    // Wait for the region in the Manager (VM0) to come online
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            WaitCriterion waitCriterion = new WaitCriterion() {

                public boolean done() {
                    Cache cache = getCache();
                    PersistentMemberManager memberManager = ((InternalCache) cache).getPersistentMemberManager();
                    return !memberManager.getWaitingRegions().isEmpty();
                }

                public String description() {
                    return "Waiting for another persistent member to come online";
                }
            };
            waitForCriterion(waitCriterion, 70000, 100, true);
        }
    });
    // Validate that there is a missing disk store on VM1
    cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    String stringResult = commandResultToString(cmdResult);
    System.out.println("command result=" + stringResult);
    assertEquals(5, countLinesInString(stringResult, false));
    assertTrue(stringContainsLine(stringResult, "Disk Store ID.*Host.*Directory"));
    assertTrue(stringContainsLine(stringResult, ".*" + diskStoreName + vm1.getPid()));
    // Extract the id from the returned missing disk store
    String line = getLineFromString(stringResult, 4);
    assertFalse(line.contains("---------"));
    StringTokenizer resultTokenizer = new StringTokenizer(line);
    String id = resultTokenizer.nextToken();
    // Remove the missing disk store and validate the result
    cmdResult = executeCommand("revoke missing-disk-store --id=" + id);
    assertNotNull(cmdResult);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    assertTrue(commandResultToString(cmdResult).contains("Missing disk store successfully revoked"));
    // Do our own cleanup so that the disk store directories can be removed
    super.destroyDefaultSetup();
    for (final VM vm : (new VM[] { vm0, vm1 })) {
        final String vmName = "VM" + vm.getPid();
        vm.invoke(new SerializableRunnable() {

            public void run() {
                try {
                    FileUtils.deleteDirectory((new File(diskStoreName + vm.getPid())));
                } catch (IOException iex) {
                // There's nothing else we can do
                }
            }
        });
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) IOException(java.io.IOException) Properties(java.util.Properties) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) PersistentMemberManager(org.apache.geode.internal.cache.persistence.PersistentMemberManager) StringTokenizer(java.util.StringTokenizer) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) RegionFactory(org.apache.geode.cache.RegionFactory) VM(org.apache.geode.test.dunit.VM) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) File(java.io.File) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 39 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class GemfireDataCommandsDUnitTest method testRegionsViaMbeanAndFunctionsForPartRgn.

@Test
public void testRegionsViaMbeanAndFunctionsForPartRgn() {
    setupWith2Regions();
    waitForListClientMbean(REBALANCE_REGION_NAME);
    final VM manager = Host.getHost(0).getVM(0);
    String memSizeFromMbean = (String) manager.invoke(new SerializableCallable() {

        public Object call() {
            Cache cache = GemFireCacheImpl.getInstance();
            DistributedRegionMXBean bean = ManagementService.getManagementService(cache).getDistributedRegionMXBean(REBALANCE_REGION_NAME);
            if (bean == null) {
                bean = ManagementService.getManagementService(cache).getDistributedRegionMXBean(Region.SEPARATOR + REBALANCE_REGION_NAME);
            }
            if (bean == null) {
                return null;
            }
            String[] membersName = bean.getMembers();
            return "" + membersName.length;
        }
    });
    getLogWriter().info("testRegionsViaMbeanAndFunctionsForPartRgn memSizeFromMbean= " + memSizeFromMbean);
    String memSizeFromFunctionCall = (String) manager.invoke(new SerializableCallable() {

        public Object call() {
            InternalCache cache = GemFireCacheImpl.getInstance();
            return "" + CliUtil.getMembersForeRegionViaFunction(cache, REBALANCE_REGION_NAME, true).size();
        }
    });
    getLogWriter().info("testRegionsViaMbeanAndFunctionsForPartRgn memSizeFromFunctionCall= " + memSizeFromFunctionCall);
    assertTrue(memSizeFromFunctionCall.equals(memSizeFromMbean));
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) InternalCache(org.apache.geode.internal.cache.InternalCache) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 40 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class GfshCommandJUnitTest method testGetMemberWithMatchingMemberId.

@Test
public void testGetMemberWithMatchingMemberId() {
    final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
    final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
    final DistributedMember mockMemberSelf = createMockMember("S", "Self");
    final DistributedMember mockMemberOne = createMockMember("1", "One");
    final DistributedMember mockMemberTwo = createMockMember("2", "Two");
    mockContext.checking(new Expectations() {

        {
            oneOf(mockCache).getMembers();
            will(returnValue(CollectionUtils.asSet(mockMemberOne, mockMemberTwo)));
            oneOf(mockCache).getDistributedSystem();
            will(returnValue(mockDistributedSystem));
            oneOf(mockDistributedSystem).getDistributedMember();
            will(returnValue(mockMemberSelf));
        }
    });
    final GfshCommand commands = createAbstractCommandsSupport(mockCache);
    assertSame(mockMemberTwo, commands.getMember(mockCache, "2"));
}
Also used : Expectations(org.jmock.Expectations) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) DistributedSystem(org.apache.geode.distributed.DistributedSystem) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

InternalCache (org.apache.geode.internal.cache.InternalCache)267 DistributedMember (org.apache.geode.distributed.DistributedMember)78 Test (org.junit.Test)64 UnitTest (org.apache.geode.test.junit.categories.UnitTest)52 IOException (java.io.IOException)48 ArrayList (java.util.ArrayList)35 HashSet (java.util.HashSet)35 CliMetaData (org.apache.geode.management.cli.CliMetaData)34 CliCommand (org.springframework.shell.core.annotation.CliCommand)34 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)32 Region (org.apache.geode.cache.Region)31 Result (org.apache.geode.management.cli.Result)30 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)30 Expectations (org.jmock.Expectations)30 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)26 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)25 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)24 Set (java.util.Set)23 ResultCollector (org.apache.geode.cache.execute.ResultCollector)22 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)20