Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4E112200D17 for ; Thu, 31 Aug 2017 03:26:00 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4C73316A554; Thu, 31 Aug 2017 01:26:00 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4C9D616A553 for ; Thu, 31 Aug 2017 03:25:59 +0200 (CEST) Received: (qmail 32526 invoked by uid 500); 31 Aug 2017 01:25:58 -0000 Mailing-List: contact commits-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list commits@geode.apache.org Received: (qmail 30698 invoked by uid 99); 31 Aug 2017 01:25:43 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 Aug 2017 01:25:43 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0ED25F55B6; Thu, 31 Aug 2017 01:25:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dschneider@apache.org To: commits@geode.apache.org Date: Thu, 31 Aug 2017 01:25:52 -0000 Message-Id: <3f68714299c84ed2b2e6f35fd29185d1@git.apache.org> In-Reply-To: <4e343206aca34d2495b7c292e7787abc@git.apache.org> References: <4e343206aca34d2495b7c292e7787abc@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [15/47] geode git commit: GEODE-3436: Restore refactoring of IndexCommands archived-at: Thu, 31 Aug 2017 01:26:00 -0000 http://git-wip-us.apache.org/repos/asf/geode/blob/0dc67f0e/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandDUnitTest.java index 5ff0a67..6dc23ce 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandDUnitTest.java @@ -23,7 +23,22 @@ import static org.apache.geode.test.dunit.Assert.assertTrue; import static org.apache.geode.test.dunit.LogWriterUtils.getDUnitLogLevel; import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.Random; +import java.util.Set; +import java.util.concurrent.atomic.AtomicLong; + import org.apache.commons.lang.StringUtils; +import org.junit.Test; +import org.junit.experimental.categories.Category; + import org.apache.geode.cache.Cache; import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.Region; @@ -43,27 +58,18 @@ import org.apache.geode.test.dunit.SerializableRunnable; import org.apache.geode.test.dunit.SerializableRunnableIF; import org.apache.geode.test.dunit.VM; import org.apache.geode.test.junit.categories.DistributedTest; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Properties; -import java.util.Random; -import java.util.Set; -import java.util.concurrent.atomic.AtomicLong; /** * The ListIndexCommandDUnitTest class is distributed test suite of test cases for testing the * index-based GemFire shell (Gfsh) commands. * * @see org.apache.geode.management.internal.cli.commands.CliCommandTestBase - * @see org.apache.geode.management.internal.cli.commands.IndexCommands + * @see org.apache.geode.management.internal.cli.commands.ClearDefinedIndexesCommand + * @see org.apache.geode.management.internal.cli.commands.CreateDefinedIndexesCommand + * @see org.apache.geode.management.internal.cli.commands.CreateIndexCommand + * @see org.apache.geode.management.internal.cli.commands.DefineIndexCommand + * @see org.apache.geode.management.internal.cli.commands.DestroyIndexCommand + * @see org.apache.geode.management.internal.cli.commands.ListIndexCommand * @since GemFire 7.0 */ @SuppressWarnings("unused") @@ -690,7 +696,7 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase { } } - private static enum CrudOperation { + private enum CrudOperation { CREATE, RETRIEVE, UPDATE, DELETE } } http://git-wip-us.apache.org/repos/asf/geode/blob/0dc67f0e/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandJUnitTest.java new file mode 100644 index 0000000..8deb4ae --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandJUnitTest.java @@ -0,0 +1,223 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.geode.management.internal.cli.commands; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import org.jmock.Expectations; +import org.jmock.Mockery; +import org.jmock.lib.concurrent.Synchroniser; +import org.jmock.lib.legacy.ClassImposteriser; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import org.apache.geode.cache.execute.Execution; +import org.apache.geode.cache.execute.FunctionInvocationTargetException; +import org.apache.geode.cache.execute.ResultCollector; +import org.apache.geode.distributed.DistributedMember; +import org.apache.geode.internal.cache.InternalCache; +import org.apache.geode.internal.cache.execute.AbstractExecution; +import org.apache.geode.internal.util.CollectionUtils; +import org.apache.geode.management.internal.cli.domain.IndexDetails; +import org.apache.geode.management.internal.cli.functions.ListIndexFunction; +import org.apache.geode.test.junit.categories.UnitTest; + +/** + * The ListIndexCommandJUnitTest class is a test suite of test cases testing the contract and + * functionality of the ListIndexCommand class. + *

+ * + * @see org.apache.geode.management.internal.cli.commands.ClearDefinedIndexesCommand + * @see org.apache.geode.management.internal.cli.commands.CreateDefinedIndexesCommand + * @see org.apache.geode.management.internal.cli.commands.CreateIndexCommand + * @see org.apache.geode.management.internal.cli.commands.DefineIndexCommand + * @see org.apache.geode.management.internal.cli.commands.DestroyIndexCommand + * @see org.apache.geode.management.internal.cli.commands.ListIndexCommand + * @see org.apache.geode.management.internal.cli.domain.IndexDetails + * @see org.apache.geode.management.internal.cli.functions.ListIndexFunction + * @see org.jmock.Expectations + * @see org.jmock.Mockery + * @see org.jmock.lib.legacy.ClassImposteriser + * @see org.junit.Assert + * @see org.junit.Test + * @since GemFire 7.0 + */ +@Category(UnitTest.class) +public class ListIndexCommandJUnitTest { + private Mockery mockContext; + + @Before + public void setup() { + mockContext = new Mockery() { + { + setImposteriser(ClassImposteriser.INSTANCE); + setThreadingPolicy(new Synchroniser()); + } + }; + } + + @After + public void tearDown() { + mockContext.assertIsSatisfied(); + mockContext = null; + } + + private ListIndexCommand createListIndexCommand(final InternalCache cache, + final Execution functionExecutor) { + return new TestListIndexCommands(cache, functionExecutor); + } + + private IndexDetails createIndexDetails(final String memberId, final String indexName) { + return new IndexDetails(memberId, "/Employees", indexName); + } + + @Test + public void testGetIndexListing() { + final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache"); + + final AbstractExecution mockFunctionExecutor = + mockContext.mock(AbstractExecution.class, "Function Executor"); + + final ResultCollector mockResultCollector = + mockContext.mock(ResultCollector.class, "ResultCollector"); + + final IndexDetails indexDetails1 = createIndexDetails("memberOne", "empIdIdx"); + final IndexDetails indexDetails2 = createIndexDetails("memberOne", "empLastNameIdx"); + final IndexDetails indexDetails3 = createIndexDetails("memberTwo", "empDobIdx"); + + final List expectedIndexDetails = + Arrays.asList(indexDetails1, indexDetails2, indexDetails3); + + final List> results = new ArrayList>(2); + + results.add(CollectionUtils.asSet(indexDetails2, indexDetails1)); + results.add(CollectionUtils.asSet(indexDetails3)); + + mockContext.checking(new Expectations() { + { + oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true))); + oneOf(mockFunctionExecutor).execute(with(aNonNull(ListIndexFunction.class))); + will(returnValue(mockResultCollector)); + oneOf(mockResultCollector).getResult(); + will(returnValue(results)); + } + }); + + final ListIndexCommand commands = createListIndexCommand(mockCache, mockFunctionExecutor); + final List actualIndexDetails = commands.getIndexListing(); + + assertNotNull(actualIndexDetails); + assertEquals(expectedIndexDetails, actualIndexDetails); + } + + @Test(expected = RuntimeException.class) + public void testGetIndexListingThrowsRuntimeException() { + final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache"); + final Execution mockFunctionExecutor = mockContext.mock(Execution.class, "Function Executor"); + + mockContext.checking(new Expectations() { + { + oneOf(mockFunctionExecutor).execute(with(aNonNull(ListIndexFunction.class))); + will(throwException(new RuntimeException("expected"))); + } + }); + + final ListIndexCommand commands = createListIndexCommand(mockCache, mockFunctionExecutor); + + try { + commands.getIndexListing(); + } catch (RuntimeException expected) { + assertEquals("expected", expected.getMessage()); + throw expected; + } + } + + @Test + public void testGetIndexListingReturnsFunctionInvocationTargetExceptionInResults() { + final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache"); + + final AbstractExecution mockFunctionExecutor = + mockContext.mock(AbstractExecution.class, "Function Executor"); + + final ResultCollector mockResultCollector = + mockContext.mock(ResultCollector.class, "ResultCollector"); + + final IndexDetails indexDetails = createIndexDetails("memberOne", "empIdIdx"); + + final List expectedIndexDetails = Collections.singletonList(indexDetails); + + final List results = new ArrayList(2); + + results.add(CollectionUtils.asSet(indexDetails)); + results.add(new FunctionInvocationTargetException("expected")); + + mockContext.checking(new Expectations() { + { + oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true))); + oneOf(mockFunctionExecutor).execute(with(aNonNull(ListIndexFunction.class))); + will(returnValue(mockResultCollector)); + oneOf(mockResultCollector).getResult(); + will(returnValue(results)); + } + }); + + final ListIndexCommand commands = createListIndexCommand(mockCache, mockFunctionExecutor); + + final List actualIndexDetails = commands.getIndexListing(); + + assertNotNull(actualIndexDetails); + assertEquals(expectedIndexDetails, actualIndexDetails); + } + + private static class TestListIndexCommands extends ListIndexCommand { + private final InternalCache cache; + private final Execution functionExecutor; + + TestListIndexCommands(final InternalCache cache, final Execution functionExecutor) { + assert cache != null : "The InternalCache cannot be null!"; + assert functionExecutor != null : "The function executor cannot be null!"; + this.cache = cache; + this.functionExecutor = functionExecutor; + } + + @Override + public InternalCache getCache() { + return this.cache; + } + + @Override + public Set getMembers(final InternalCache cache) { + assertSame(getCache(), cache); + return Collections.emptySet(); + } + + @Override + public Execution getMembersFunctionExecutor(final Set members) { + Assert.assertNotNull(members); + return functionExecutor; + } + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/0dc67f0e/geode-core/src/test/java/org/apache/geode/management/internal/security/TestCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/TestCommand.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/TestCommand.java index 853853b..4efa93f 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/security/TestCommand.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/TestCommand.java @@ -200,7 +200,8 @@ public class TestCommand { createTestCommand("hint"); createTestCommand("help"); - // IndexCommands + // ClearDefinedIndexesCommand, CreateDefinedIndexesCommand, CreateIndexCommand, + // DefineIndexCommand, DestroyIndexCommand, ListIndexCommand createTestCommand("clear defined indexes", clusterManageQuery); createTestCommand("create defined indexes", clusterManageQuery); createTestCommand(