Search in sources :

Example 71 with Parameters

use of junitparams.Parameters in project geode by apache.

the class LuceneIndexCommandsJUnitTest method testDestroyAllIndexesWithRegionMembers.

@Test
@Parameters({ "true", "false" })
public void testDestroyAllIndexesWithRegionMembers(boolean expectedToSucceed) throws Exception {
    LuceneIndexCommands commands = createTestLuceneIndexCommandsForDestroyIndex();
    String indexName = null;
    String regionPath = "regionPath";
    Set<DistributedMember> members = new HashSet<>();
    DistributedMember mockMember = mock(DistributedMember.class);
    when(mockMember.getId()).thenReturn("member0");
    members.add(mockMember);
    final ResultCollector mockResultCollector = mock(ResultCollector.class);
    final List<CliFunctionResult> cliFunctionResults = new ArrayList<>();
    String expectedStatus;
    if (expectedToSucceed) {
        expectedStatus = CliStrings.format(LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__SUCCESSFULLY_DESTROYED_INDEXES_FROM_REGION_0, new Object[] { regionPath });
        cliFunctionResults.add(new CliFunctionResult(mockMember.getId()));
    } else {
        Exception e = new IllegalStateException("failed");
        expectedStatus = e.getMessage();
        cliFunctionResults.add(new CliFunctionResult("member0", e, e.getMessage()));
    }
    doReturn(mockResultCollector).when(commands).executeFunction(isA(LuceneDestroyIndexFunction.class), any(LuceneDestroyIndexInfo.class), any());
    doReturn(cliFunctionResults).when(mockResultCollector).getResult();
    doReturn(Collections.emptySet()).when(commands).getNormalMembers(any());
    doReturn(Collections.emptySet()).when(commands).getRegionMembers(any(), any());
    CommandResult result = (CommandResult) commands.destroyIndex(indexName, regionPath);
    verifyDestroyIndexCommandResult(result, cliFunctionResults, expectedStatus);
}
Also used : LuceneDestroyIndexFunction(org.apache.geode.cache.lucene.internal.cli.functions.LuceneDestroyIndexFunction) ArrayList(java.util.ArrayList) Mockito.anyString(org.mockito.Mockito.anyString) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) DistributedMember(org.apache.geode.distributed.DistributedMember) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet) Parameters(junitparams.Parameters) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 72 with Parameters

use of junitparams.Parameters in project geode by apache.

the class LuceneIndexCommandsDUnitTest method testDestroyAllIndexes.

@Test
@Parameters({ "true", "false" })
public void testDestroyAllIndexes(boolean createRegion) throws Exception {
    final VM vm1 = Host.getHost(0).getVM(1);
    if (createRegion) {
        createIndex(vm1);
    } else {
        createIndexWithoutRegion(vm1);
    }
    CommandResult result = createAndExecuteDestroyIndexCommand(null, REGION_NAME);
    String resultAsString = commandResultToString(result);
    String expectedStatus = CliStrings.format(LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__SUCCESSFULLY_DESTROYED_INDEXES_FROM_REGION_0, new Object[] { REGION_NAME });
    assertTrue(resultAsString.contains(expectedStatus));
}
Also used : VM(org.apache.geode.test.dunit.VM) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Parameters(junitparams.Parameters) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 73 with Parameters

use of junitparams.Parameters in project geode by apache.

the class LuceneIndexCommandsDUnitTest method testDestroySingleIndex.

@Test
@Parameters({ "true", "false" })
public void testDestroySingleIndex(boolean createRegion) throws Exception {
    final VM vm1 = Host.getHost(0).getVM(1);
    if (createRegion) {
        createIndex(vm1);
    } else {
        createIndexWithoutRegion(vm1);
    }
    CommandResult result = createAndExecuteDestroyIndexCommand(INDEX_NAME, REGION_NAME);
    String resultAsString = commandResultToString(result);
    String expectedStatus = CliStrings.format(LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__SUCCESSFULLY_DESTROYED_INDEX_0_FROM_REGION_1, new Object[] { INDEX_NAME, REGION_NAME });
    assertTrue(resultAsString.contains(expectedStatus));
}
Also used : VM(org.apache.geode.test.dunit.VM) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Parameters(junitparams.Parameters) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 74 with Parameters

use of junitparams.Parameters in project geode by apache.

the class LuceneIndexCommandsJUnitTest method testDestroyAllIndexesNoRegionMembers.

@Test
@Parameters({ "true", "false" })
public void testDestroyAllIndexesNoRegionMembers(boolean expectedToSucceed) throws Exception {
    LuceneIndexCommands commands = createTestLuceneIndexCommandsForDestroyIndex();
    String indexName = null;
    String regionPath = "regionPath";
    final ResultCollector mockResultCollector = mock(ResultCollector.class);
    final List<CliFunctionResult> cliFunctionResults = new ArrayList<>();
    String expectedStatus;
    if (expectedToSucceed) {
        expectedStatus = CliStrings.format(LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__SUCCESSFULLY_DESTROYED_INDEXES_FROM_REGION_0, new Object[] { regionPath });
        cliFunctionResults.add(new CliFunctionResult("member0"));
    } else {
        Exception e = new IllegalStateException("failed");
        expectedStatus = e.getMessage();
        cliFunctionResults.add(new CliFunctionResult("member0", e, e.getMessage()));
    }
    doReturn(mockResultCollector).when(commands).executeFunction(isA(LuceneDestroyIndexFunction.class), any(LuceneDestroyIndexInfo.class), any());
    doReturn(cliFunctionResults).when(mockResultCollector).getResult();
    doReturn(Collections.emptySet()).when(commands).getNormalMembers(any());
    doReturn(Collections.emptySet()).when(commands).getRegionMembers(any(), any());
    CommandResult result = (CommandResult) commands.destroyIndex(indexName, regionPath);
    verifyDestroyIndexCommandResult(result, cliFunctionResults, expectedStatus);
}
Also used : CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) LuceneDestroyIndexFunction(org.apache.geode.cache.lucene.internal.cli.functions.LuceneDestroyIndexFunction) ArrayList(java.util.ArrayList) Mockito.anyString(org.mockito.Mockito.anyString) ResultCollector(org.apache.geode.cache.execute.ResultCollector) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Parameters(junitparams.Parameters) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

Parameters (junitparams.Parameters)74 Test (org.junit.Test)74 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)55 SerializableRunnableIF (org.apache.geode.test.dunit.SerializableRunnableIF)41 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)11 Region (org.apache.geode.cache.Region)10 Cache (org.apache.geode.cache.Cache)9 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)9 DistributedMember (org.apache.geode.distributed.DistributedMember)8 UnitTest (org.apache.geode.test.junit.categories.UnitTest)7 ArrayList (java.util.ArrayList)6 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)5 List (java.util.List)4 ResultCollector (org.apache.geode.cache.execute.ResultCollector)4 LuceneDestroyIndexFunction (org.apache.geode.cache.lucene.internal.cli.functions.LuceneDestroyIndexFunction)4 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)4 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)4 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)4 Mockito.anyString (org.mockito.Mockito.anyString)4 File (java.io.File)3