geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jensde...@apache.org
Subject [geode] branch develop updated: GEODE-3763: Refactor ListIndexCommandDUnitTest to use rules (#894)
Date Mon, 09 Oct 2017 17:30:19 GMT
This is an automated email from the ASF dual-hosted git repository.

jensdeppe pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 663d9b3  GEODE-3763: Refactor ListIndexCommandDUnitTest to use rules (#894)
663d9b3 is described below

commit 663d9b3c1ce87423a33bc528309038e8e6565301
Author: Jens Deppe <jdeppe@pivotal.io>
AuthorDate: Mon Oct 9 10:30:16 2017 -0700

    GEODE-3763: Refactor ListIndexCommandDUnitTest to use rules (#894)
---
 .../internal/cli/domain/IndexDetails.java          |   6 +-
 .../cli/commands/ListIndexCommandDUnitTest.java    | 712 ++-------------------
 .../cli/domain/IndexDetailsIntegrationTest.java    |  79 +++
 .../geode/codeAnalysis/sanctionedSerializables.txt |   6 +-
 .../cli/commands/CommandOverHttpDUnitTest.java     |   7 +-
 .../ListIndexCommandOverHttpDUnitTest.java         |  29 +
 6 files changed, 166 insertions(+), 673 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/domain/IndexDetails.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/domain/IndexDetails.java
index 8dc67b6..f79c859 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/domain/IndexDetails.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/domain/IndexDetails.java
@@ -47,7 +47,7 @@ public class IndexDetails implements Comparable<IndexDetails>, Serializable
{
   private String projectionAttributes;
   private String memberName;
   private String regionName;
-  private String isValid;
+  private boolean isValid;
 
   private final String indexName;
   private final String memberId;
@@ -98,7 +98,7 @@ public class IndexDetails implements Comparable<IndexDetails>, Serializable
{
   }
 
   public void setIsValid(boolean valid) {
-    this.isValid = String.valueOf(valid);
+    this.isValid = valid;
   }
 
   public IndexDetails(final String memberId, final String regionPath, final String indexName)
{
@@ -186,7 +186,7 @@ public class IndexDetails implements Comparable<IndexDetails>, Serializable
{
     return regionPath;
   }
 
-  public String getIsValid() {
+  public boolean getIsValid() {
     return this.isValid;
   }
 
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 226925f..fbddcb1 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
@@ -12,692 +12,80 @@
  * 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.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
-import static org.apache.geode.distributed.ConfigurationProperties.NAME;
-import static org.apache.geode.test.dunit.Assert.assertEquals;
-import static org.apache.geode.test.dunit.Assert.assertNotNull;
-import static org.apache.geode.test.dunit.Assert.assertSame;
-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;
+package org.apache.geode.management.internal.cli.commands;
 
-import org.apache.commons.lang.StringUtils;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import static org.assertj.core.api.Assertions.assertThat;
 
 import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.DataPolicy;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.RegionFactory;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.cache.query.Index;
-import org.apache.geode.cache.query.IndexStatistics;
-import org.apache.geode.cache.query.IndexType;
-import org.apache.geode.cache.query.SelectResults;
-import org.apache.geode.internal.lang.MutableIdentifiable;
-import org.apache.geode.internal.lang.ObjectUtils;
-import org.apache.geode.management.cli.Result;
-import org.apache.geode.management.internal.cli.domain.IndexDetails;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.management.internal.cli.domain.Stock;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
-import org.apache.geode.test.dunit.Host;
-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.management.internal.cli.json.GfJsonObject;
+import org.apache.geode.management.internal.cli.result.CommandResult;
+import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
 import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.FlakyTest;
-
-/**
- * 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.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
- */
-@Category({DistributedTest.class, FlakyTest.class}) // GEODE-3530
-@SuppressWarnings("serial")
-public class ListIndexCommandDUnitTest extends CliCommandTestBase {
-
-  private static final int DEFAULT_REGION_INITIAL_CAPACITY = 10000;
-
-  private final AtomicLong idGenerator = new AtomicLong(0L);
-
-  @Override
-  public final void postSetUpCliCommandTestBase() throws Exception {
-    setUpJmxManagerOnVm0ThenConnect(null);
-    setupGemFire();
-  }
-
-  private static String toString(final Result result) {
-    assert result != null : "The Result object from the command execution cannot be null!";
-
-    final StringBuilder buffer = new StringBuilder(System.getProperty("line.separator"));
-
-    while (result.hasNextLine()) {
-      buffer.append(result.nextLine());
-      buffer.append(System.getProperty("line.separator"));
-    }
-
-    return buffer.toString();
-  }
-
-  private Index createIndex(final String name, final String indexedExpression,
-      final String fromClause) {
-    return createIndex(name, IndexType.FUNCTIONAL, indexedExpression, fromClause);
-  }
-
-  private Index createIndex(final String name, final IndexType type, final String indexedExpression,
-      final String fromClause) {
-    return new IndexAdapter(name, type, indexedExpression, fromClause);
-  }
-
-  private Peer createPeer(final VM vm, final Properties distributedSystemProperties,
-      final RegionDefinition... regions) {
-    final Peer peer = new Peer(vm, distributedSystemProperties);
-    peer.add(regions);
-    return peer;
-  }
-
-  private RegionDefinition createRegionDefinition(final String regionName,
-      final Class<?> keyConstraint, final Class<?> valueConstraint, final Index...
indexes) {
-    final RegionDefinition regionDefinition =
-        new RegionDefinition(regionName, keyConstraint, valueConstraint);
-    regionDefinition.add(indexes);
-    return regionDefinition;
-  }
-
-  private void setupGemFire() throws Exception {
-    final Host host = Host.getHost(0);
-
-    final VM vm1 = host.getVM(1);
-    final VM vm2 = host.getVM(2);
-
-    final Peer peer1 = createPeer(vm1, createDistributedSystemProperties("consumerServer"),
-        createRegionDefinition("consumers", Long.class, Consumer.class,
-            createIndex("cidIdx", IndexType.PRIMARY_KEY, "id", "/consumers"),
-            createIndex("cnameIdx", "name", "/consumers")));
-
-    final Peer peer2 =
-        createPeer(vm2, createDistributedSystemProperties("producerServer"), createRegionDefinition(
-            "producers", Long.class, Producer.class, createIndex("pidIdx", "id", "/producers")));
-
-    createRegionWithIndexes(peer1);
-    createRegionWithIndexes(peer2);
-
-    loadConsumerData(peer1, 10000);
-    loadProducerData(peer2, 10000);
-  }
-
-  private Properties createDistributedSystemProperties(final String gemfireName) {
-    final Properties distributedSystemProperties = new Properties();
-
-    distributedSystemProperties.setProperty(LOG_LEVEL, getDUnitLogLevel());
-    distributedSystemProperties.setProperty(NAME, gemfireName);
-
-    return distributedSystemProperties;
-  }
-
-  private void createRegionWithIndexes(final Peer peer) throws Exception {
-    peer.run(new SerializableRunnable(
-        String.format("Creating Regions with Indexes on GemFire peer (%1$s).", peer.getName()))
{
-      public void run() {
-        // create the GemFire distributed system with custom configuration properties...
-        getSystem(peer.getConfiguration());
-
-        final Cache cache = getCache();
-        final RegionFactory regionFactory = cache.createRegionFactory();
-
-        for (RegionDefinition regionDefinition : peer) {
-          regionFactory.setDataPolicy(DataPolicy.REPLICATE);
-          regionFactory.setIndexMaintenanceSynchronous(true);
-          regionFactory.setInitialCapacity(DEFAULT_REGION_INITIAL_CAPACITY);
-          regionFactory.setKeyConstraint(regionDefinition.getKeyConstraint());
-          regionFactory.setScope(Scope.DISTRIBUTED_NO_ACK);
-          regionFactory.setStatisticsEnabled(true);
-          regionFactory.setValueConstraint(regionDefinition.getValueConstraint());
-
-          final Region region = regionFactory.create(regionDefinition.getRegionName());
-          String indexName = null;
-
-          try {
-            for (Index index : regionDefinition) {
-              indexName = index.getName();
-              if (IndexType.PRIMARY_KEY.equals(index.getType())) {
-                cache.getQueryService().createKeyIndex(indexName, index.getIndexedExpression(),
-                    region.getFullPath());
-              } else {
-                cache.getQueryService().createIndex(indexName, index.getIndexedExpression(),
-                    region.getFullPath());
-              }
-            }
-          } catch (Exception e) {
-            getLogWriter().error(
-                String.format("Error occurred creating Index (%1$s) on Region (%2$s) - (%3$s)",
-                    indexName, region.getFullPath(), e.getMessage()));
-          }
-        }
-      }
-    });
-  }
-
-  private void loadConsumerData(final Peer peer, final int operationsTotal) throws Exception
{
-    peer.run(new SerializableRunnable("Load /consumers Region with data") {
-      public void run() {
-        final Cache cache = getCache();
-        final Region<Long, Consumer> consumerRegion = cache.getRegion("/consumers");
-
-        final Random random = new Random(System.currentTimeMillis());
-        int count = 0;
+import org.apache.geode.test.junit.rules.GfshShellConnectionRule;
+import org.json.JSONArray;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
-        final List<Proxy> proxies = new ArrayList<>();
+@Category(DistributedTest.class)
+public class ListIndexCommandDUnitTest {
 
-        Consumer consumer;
-        Proxy proxy;
+  private static final String REGION_1 = "REGION1";
+  private static final String INDEX_REGION_NAME = "/REGION1";
+  private static final String INDEX_1 = "INDEX1";
 
-        while (count++ < operationsTotal) {
-          switch (CrudOperation.values()[random.nextInt(CrudOperation.values().length)])
{
-            case RETRIEVE:
-              if (!proxies.isEmpty()) {
-                proxy = proxies.get(random.nextInt(proxies.size()));
-                consumer = query(consumerRegion, "id = " + proxy.getId() + "l"); // works
-                // consumer = query(consumerRegion, "Id = " + proxy.getId()); // works
-                // consumer = query(consumerRegion, "id = " + proxy.getId()); // does not
work
-                proxy.setUnitsSnapshot(consumer.getUnits());
-                break;
-              }
-            case UPDATE:
-              if (!proxies.isEmpty()) {
-                proxy = proxies.get(random.nextInt(proxies.size()));
-                consumer = query(consumerRegion, "Name = " + proxy.getName());
-                consumer.consume();
-                break;
-              }
-            case CREATE:
-            default:
-              consumer = new Consumer(idGenerator.incrementAndGet());
-              proxies.add(new Proxy(consumer));
-              consumerRegion.put(consumer.getId(), consumer);
-              assertTrue(consumerRegion.containsKey(consumer.getId()));
-              assertTrue(consumerRegion.containsValueForKey(consumer.getId()));
-              assertSame(consumer, consumerRegion.get(consumer.getId()));
-          }
-        }
-      }
-    });
-  }
+  private MemberVM locator, server;
 
-  private void loadProducerData(final Peer peer, final int operationsTotal) throws Exception
{
-    peer.run(new SerializableRunnable("Load /producers Region with data") {
-      public void run() {
-        final Cache cache = getCache();
-        final Region<Long, Producer> producerRegion = cache.getRegion("/producers");
+  @Rule
+  public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
 
-        final Random random = new Random(System.currentTimeMillis());
-        int count = 0;
+  @Rule
+  public GfshShellConnectionRule gfsh = new GfshShellConnectionRule();
 
-        final List<Proxy> proxies = new ArrayList<>();
+  @Before
+  public void before() throws Exception {
+    locator = lsRule.startLocatorVM(0);
+    server = lsRule.startServerVM(1, locator.getPort());
 
-        Producer producer;
-        Proxy proxy;
+    server.invoke(() -> {
+      Cache cache = LocatorServerStartupRule.serverStarter.getCache();
+      RegionFactory factory = cache.createRegionFactory(RegionShortcut.REPLICATE);
+      Region region = factory.create(REGION_1);
 
-        while (count++ < operationsTotal) {
-          switch (CrudOperation.values()[random.nextInt(CrudOperation.values().length)])
{
-            case RETRIEVE:
-              if (!proxies.isEmpty()) {
-                proxy = proxies.get(random.nextInt(proxies.size()));
-                producer = query(producerRegion, "Id = " + proxy.getId());
-                proxy.setUnitsSnapshot(producer.getUnits());
-                break;
-              }
-            case UPDATE:
-              if (!proxies.isEmpty()) {
-                proxy = proxies.get(random.nextInt(proxies.size()));
-                producer = query(producerRegion, "Id = " + proxy.getId());
-                producer.produce();
-                break;
-              }
-            case CREATE:
-            default:
-              producer = new Producer(idGenerator.incrementAndGet());
-              proxies.add(new Proxy(producer));
-              producerRegion.put(producer.getId(), producer);
-              assertTrue(producerRegion.containsKey(producer.getId()));
-              assertTrue(producerRegion.containsValueForKey(producer.getId()));
-              assertSame(producer, producerRegion.get(producer.getId()));
-          }
-        }
-      }
+      cache.getQueryService().createIndex(INDEX_1, "key", INDEX_REGION_NAME);
+      region.put(1, new Stock("SUNW", 10));
+      region.get(1);
     });
-  }
-
-  @SuppressWarnings("unchecked")
-  private <T extends Comparable<T>, B extends AbstractBean<T>> B query(final
Cache cache,
-      final String queryString) {
-    try {
-      getLogWriter().info(String.format("Running Query (%1$s) in GemFire...", queryString));
 
-      final SelectResults<B> results =
-          (SelectResults<B>) cache.getQueryService().newQuery(queryString).execute();
-
-      getLogWriter()
-          .info(String.format("Running Query (%1$s) in GemFire returned (%2$d) result(s).",
-              queryString, results.size()));
-
-      return (results.iterator().hasNext() ? results.iterator().next() : null);
-    } catch (Exception e) {
-      throw new RuntimeException(
-          String.format("An error occurred running Query (%1$s)!", queryString), e);
-    }
+    connectGfsh(locator);
   }
 
-  private <T extends Comparable<T>, B extends AbstractBean<T>> B query(final
Region<T, B> region,
-      final String queryPredicate) {
-    try {
-      getLogWriter().info(String.format("Running Query (%1$s) on Region (%2$s)...", queryPredicate,
-          region.getFullPath()));
-
-      final SelectResults<B> results = region.query(queryPredicate);
-
-      getLogWriter()
-          .info(String.format("Running Query (%1$s) on Region (%2$s) returned (%3$d) result(s).",
-              queryPredicate, region.getFullPath(), results.size()));
-
-      return (results.iterator().hasNext() ? results.iterator().next() : null);
-    } catch (Exception e) {
-      throw new RuntimeException(
-          String.format("An error occurred running Query (%1$s) on Region (%2$s)!", queryPredicate,
-              region.getFullPath()),
-          e);
-    }
+  public void connectGfsh(MemberVM vm) throws Exception {
+    gfsh.connectAndVerify(vm.getJmxPort(), GfshShellConnectionRule.PortType.jmxManager);
   }
 
   @Test
-  public void testListIndex() throws Exception {
-    final Result result =
-        executeCommand(CliStrings.LIST_INDEX + " --" + CliStrings.LIST_INDEX__STATS);
-
-    assertNotNull(result);
-    getLogWriter().info(toString(result));
-    assertEquals(Result.Status.OK, result.getStatus());
-  }
-
-  private static class Peer implements Iterable<RegionDefinition>, Serializable {
-
-    private final Properties distributedSystemProperties;
-
-    private final Set<RegionDefinition> regions = new HashSet<>();
-
-    private final VM vm;
-
-    public Peer(final VM vm, final Properties distributedSystemProperties) {
-      assert distributedSystemProperties != null : "The GemFire Distributed System configuration
properties cannot be null!";
-      this.distributedSystemProperties = distributedSystemProperties;
-      this.vm = vm;
-    }
-
-    public Properties getConfiguration() {
-      return this.distributedSystemProperties;
-    }
-
-    public String getName() {
-      return getConfiguration().getProperty(NAME);
-    }
-
-    public VM getVm() {
-      return vm;
-    }
-
-    public boolean add(final RegionDefinition... regionDefinitions) {
-      return (regionDefinitions != null && regions.addAll(Arrays.asList(regionDefinitions)));
-    }
-
-    @Override
-    public Iterator<RegionDefinition> iterator() {
-      return Collections.unmodifiableSet(regions).iterator();
-    }
-
-    public boolean remove(final RegionDefinition... regionDefinitions) {
-      return (regionDefinitions != null && regions.removeAll(Arrays.asList(regionDefinitions)));
-    }
-
-    public void run(final SerializableRunnableIF runnable) throws Exception {
-      if (getVm() == null) {
-        runnable.run();
-      } else {
-        getVm().invoke(runnable);
-      }
-    }
-
-    @Override
-    public String toString() {
-      final StringBuilder buffer = new StringBuilder(getClass().getSimpleName());
-      buffer.append(" {configuration = ").append(getConfiguration());
-      buffer.append(", name = ").append(getName());
-      buffer.append(", pid = ").append(getVm().getPid());
-      buffer.append("}");
-      return buffer.toString();
-    }
-  }
-
-  private static class IndexAdapter implements Index, Serializable {
-
-    private final IndexDetails.IndexType type;
-
-    private final String fromClause;
-    private final String indexedExpression;
-    private final String name;
-
-    protected IndexAdapter(final String name, final String indexedExpression,
-        final String fromClause) {
-      this(name, IndexType.FUNCTIONAL, indexedExpression, fromClause);
-    }
-
-    protected IndexAdapter(final String name, final IndexType type, final String indexedExpression,
-        final String fromClause) {
-      assert name != null : "The name of the Index cannot be null!";
-      assert indexedExpression != null : String
-          .format("The expression to index for Index (%1$s) cannot be null!", name);
-      assert fromClause != null : String.format("The from clause for Index (%1$s) cannot
be null!",
-          name);
-
-      this.type = ObjectUtils.defaultIfNull(IndexDetails.IndexType.valueOf(type),
-          IndexDetails.IndexType.FUNCTIONAL);
-      this.name = name;
-      this.indexedExpression = indexedExpression;
-      this.fromClause = fromClause;
-    }
-
-    @Override
-    public String getName() {
-      return this.name;
-    }
-
-    @Override
-    public String getFromClause() {
-      return this.fromClause;
-    }
-
-    @Override
-    public String getCanonicalizedFromClause() {
-      return this.fromClause;
-    }
-
-    @Override
-    public String getIndexedExpression() {
-      return this.indexedExpression;
-    }
-
-    @Override
-    public String getCanonicalizedIndexedExpression() {
-      return this.indexedExpression;
-    }
-
-    @Override
-    public String getProjectionAttributes() {
-      throw new UnsupportedOperationException("Not Implemented!");
-    }
-
-    @Override
-    public String getCanonicalizedProjectionAttributes() {
-      throw new UnsupportedOperationException("Not Implemented!");
-    }
-
-    @Override
-    public Region<?, ?> getRegion() {
-      throw new UnsupportedOperationException("Not Implemented!");
-    }
-
-    @Override
-    public IndexStatistics getStatistics() {
-      throw new UnsupportedOperationException("Not Implemented!");
-    }
-
-    @Override
-    public IndexType getType() {
-      return type.getType();
-    }
-
-    @Override
-    public String toString() {
-      final StringBuilder buffer = new StringBuilder(getClass().getSimpleName());
-      buffer.append(" {indexName = ").append(getName());
-      buffer.append(", indexType = ").append(getType());
-      buffer.append(", indexedExpression = ").append(getIndexedExpression());
-      buffer.append(", fromClause = ").append(getFromClause());
-      buffer.append("}");
-      return buffer.toString();
-    }
+  public void testListIndexes() throws Exception {
+    CommandResult result = gfsh.executeAndVerifyCommand(CliStrings.LIST_INDEX);
+    assertThat(((JSONArray) result.getContent().get("Member Name")).get(0))
+        .isEqualTo(server.getName());
   }
 
-  private static class RegionDefinition implements Iterable<Index>, Serializable {
-
-    private final Class<?> keyConstraint;
-    private final Class<?> valueConstraint;
-
-    private final Set<Index> indexes = new HashSet<>();
-
-    private final String regionName;
-
-    @SuppressWarnings("unchecked")
-    protected RegionDefinition(final String regionName, final Class<?> keyConstraint,
-        final Class<?> valueConstraint) {
-      assert StringUtils.isNotBlank(regionName) : "The name of the Region must be specified!";
-      this.regionName = regionName;
-      this.keyConstraint = ObjectUtils.defaultIfNull(keyConstraint, Object.class);
-      this.valueConstraint = ObjectUtils.defaultIfNull(valueConstraint, Object.class);
-    }
-
-    public String getRegionName() {
-      return regionName;
-    }
-
-    public Class<?> getKeyConstraint() {
-      return keyConstraint;
-    }
-
-    public Class<?> getValueConstraint() {
-      return valueConstraint;
-    }
-
-    public boolean add(final Index... indexes) {
-      return (indexes != null && this.indexes.addAll(Arrays.asList(indexes)));
-    }
-
-    @Override
-    public Iterator<Index> iterator() {
-      return Collections.unmodifiableSet(indexes).iterator();
-    }
-
-    public boolean remove(final Index... indexes) {
-      return (indexes != null && this.indexes.removeAll(Arrays.asList(indexes)));
-    }
-
-    @Override
-    public boolean equals(final Object obj) {
-      if (obj == this) {
-        return true;
-      }
-
-      if (!(obj instanceof RegionDefinition)) {
-        return false;
-      }
-
-      final RegionDefinition that = (RegionDefinition) obj;
-
-      return ObjectUtils.equals(getRegionName(), that.getRegionName());
-    }
-
-    @Override
-    public int hashCode() {
-      int hashValue = 17;
-      hashValue = 37 * hashValue + ObjectUtils.hashCode(getRegionName());
-      return hashValue;
-    }
-
-    @Override
-    public String toString() {
-      final StringBuilder buffer = new StringBuilder(getClass().getSimpleName());
-      buffer.append(" {regionName = ").append(getRegionName());
-      buffer.append(", keyConstraint = ").append(getKeyConstraint());
-      buffer.append(", valueConstraint = ").append(getValueConstraint());
-      buffer.append("}");
-      return buffer.toString();
-    }
-  }
-
-  private abstract static class AbstractBean<T extends Comparable<T>>
-      implements MutableIdentifiable<T>, Serializable {
-
-    private T id;
-    private String name;
-
-    public AbstractBean() {}
-
-    public AbstractBean(final T id) {
-      this.id = id;
-    }
-
-    @Override
-    public T getId() {
-      return id;
-    }
-
-    @Override
-    public void setId(final T id) {
-      this.id = id;
-    }
-
-    public String getName() {
-      return name;
-    }
-
-    public void setName(final String name) {
-      this.name = name;
-    }
-
-    @Override
-    public boolean equals(final Object obj) {
-      if (obj == this) {
-        return true;
-      }
-
-      if (!(getClass().isInstance(obj))) {
-        return false;
-      }
-
-      final AbstractBean bean = (AbstractBean) obj;
-
-      return ObjectUtils.equals(getId(), bean.getId());
-    }
-
-    @Override
-    public int hashCode() {
-      int hashValue = 17;
-      hashValue = 37 * hashValue + ObjectUtils.hashCode(getId());
-      return hashValue;
-    }
-
-    @Override
-    public String toString() {
-      final StringBuilder buffer = new StringBuilder(getClass().getSimpleName());
-      buffer.append(" {id = ").append(getId());
-      buffer.append(", name = ").append(getName());
-      buffer.append("}");
-      return buffer.toString();
-    }
-  }
-
-  public static class Consumer extends AbstractBean<Long> {
-
-    private volatile int units;
-
-    public Consumer() {}
-
-    public Consumer(final Long id) {
-      super(id);
-    }
-
-    public int getUnits() {
-      return units;
-    }
-
-    public int consume() {
-      return ++units;
-    }
-  }
-
-  public static class Producer extends AbstractBean<Long> {
-
-    private volatile int units;
-
-    public Producer() {}
-
-    public Producer(final Long id) {
-      super(id);
-    }
-
-    public int getUnits() {
-      return units;
-    }
-
-    public int produce() {
-      return ++units;
-    }
-  }
-
-  private static class Proxy extends AbstractBean<Long> {
-
-    private final AbstractBean<Long> bean;
-    private int unitsSnapshot;
-
-    public Proxy(final AbstractBean<Long> bean) {
-      assert bean != null : "The bean to proxy cannot be null!";
-      this.bean = bean;
-    }
-
-    public AbstractBean<Long> getBean() {
-      return bean;
-    }
-
-    @Override
-    public Long getId() {
-      return getBean().getId();
-    }
-
-    @Override
-    public String getName() {
-      return getBean().getName();
-    }
-
-    public int getUnitsSnapshot() {
-      return unitsSnapshot;
-    }
-
-    public void setUnitsSnapshot(final int unitsSnapshot) {
-      this.unitsSnapshot = unitsSnapshot;
-    }
-  }
-
-  private enum CrudOperation {
-    CREATE, RETRIEVE, UPDATE, DELETE
+  @Test
+  public void testListIndexesWithStats() throws Exception {
+    CommandResult result = gfsh.executeAndVerifyCommand(CliStrings.LIST_INDEX + " --with-stats");
+    GfJsonObject content = result.getContent();
+    assertThat(((JSONArray) content.get("Member Name")).get(0)).isEqualTo(server.getName());
+    assertThat(((JSONArray) content.get("Updates")).get(0)).isEqualTo("1");
+    assertThat(((JSONArray) content.get("Keys")).get(0)).isEqualTo("1");
+    assertThat(((JSONArray) content.get("Values")).get(0)).isEqualTo("1");
   }
 }
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/domain/IndexDetailsIntegrationTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/domain/IndexDetailsIntegrationTest.java
new file mode 100644
index 0000000..d43b13f
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/domain/IndexDetailsIntegrationTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.domain;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.distributed.DistributedMember;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.apache.geode.test.junit.rules.ServerStarterRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(IntegrationTest.class)
+public class IndexDetailsIntegrationTest {
+
+  private static final String REGION_1 = "REGION1";
+  private static final String INDEX_REGION_NAME = "/REGION1";
+  private static final String INDEX_1 = "INDEX1";
+
+  private Region region;
+
+  @Rule
+  public ServerStarterRule serverRule =
+      new ServerStarterRule().withRegion(RegionShortcut.REPLICATE, REGION_1);
+
+  @Before
+  public void before() throws Exception {
+    Cache cache = serverRule.getCache();
+    region = cache.getRegion(REGION_1);
+
+    cache.getQueryService().createIndex(INDEX_1, "key", INDEX_REGION_NAME);
+    region.put(1, new Stock("SUNW", 10));
+    region.get(1);
+  }
+
+  @Test
+  public void basicAttributes() {
+    Cache cache = serverRule.getCache();
+    Index idx = cache.getQueryService().getIndex(region, INDEX_1);
+    DistributedMember member = cache.getDistributedSystem().getDistributedMember();
+
+    IndexDetails details = new IndexDetails(member, idx);
+    assertThat(details).isNotNull();
+
+    assertThat(details.getIndexName()).isEqualTo(INDEX_1);
+    assertThat(details.getRegionPath()).isEqualTo(INDEX_REGION_NAME);
+    assertThat(details.getMemberId()).isEqualTo(member.getId());
+    assertThat(details.getMemberName()).isEqualTo(member.getName());
+    assertThat(details.getFromClause()).isEqualTo(INDEX_REGION_NAME);
+    assertThat(details.getIndexedExpression()).isEqualTo("key");
+    assertThat(details.getIndexType()).isEqualTo(IndexDetails.IndexType.FUNCTIONAL);
+    assertThat(details.getProjectionAttributes()).isEqualTo("*");
+    assertThat(details.getIsValid()).isEqualTo(true);
+
+    IndexDetails.IndexStatisticsDetails stats = details.getIndexStatisticsDetails();
+    assertThat(stats.getNumberOfKeys()).isEqualTo(1);
+    assertThat(stats.getNumberOfUpdates()).isEqualTo(1);
+    assertThat(stats.getNumberOfValues()).isEqualTo(1);
+  }
+}
diff --git a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt
b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt
index 50a4014..ca9b846 100755
--- a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt
+++ b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt
@@ -488,7 +488,6 @@ org/apache/geode/management/cli/CommandProcessingException,true,-139877952163957
 org/apache/geode/management/cli/CommandServiceException,true,7316102209844678329
 org/apache/geode/management/cli/Result$Status,false,code:int
 org/apache/geode/management/internal/JmxManagerLocator$StartJmxManagerFunction,true,-2860286061903069789
-org/apache/geode/management/internal/ManagementAgent$GemFireRMIClientSocketFactory,true,-7604285019188827617
 org/apache/geode/management/internal/ManagementAgent$GemFireRMIServerSocketFactory,true,-811909050641332716,bindAddr:java/net/InetAddress
 org/apache/geode/management/internal/ManagementFunction,true,1,mbeanServer:javax/management/MBeanServer,notificationHub:org/apache/geode/management/internal/NotificationHub
 org/apache/geode/management/internal/NotificationKey,false,currentTime:long,objectName:javax/management/ObjectName
@@ -512,7 +511,7 @@ org/apache/geode/management/internal/cli/domain/DiskStoreDetails$RegionDetails,f
 org/apache/geode/management/internal/cli/domain/DurableCqNamesResult,true,1,cqNames:java/util/List
 org/apache/geode/management/internal/cli/domain/EvictionAttributesInfo,true,1,evictionAction:java/lang/String,evictionAlgorithm:java/lang/String,evictionMaxValue:int,nonDefaultAttributes:java/util/Map
 org/apache/geode/management/internal/cli/domain/FixedPartitionAttributesInfo,true,1,isPrimary:boolean,numBuckets:int,partitionName:java/lang/String
-org/apache/geode/management/internal/cli/domain/IndexDetails,true,-2198907141534201288,fromClause:java/lang/String,indexName:java/lang/String,indexStatisticsDetails:org/apache/geode/management/internal/cli/domain/IndexDetails$IndexStatisticsDetails,indexType:org/apache/geode/management/internal/cli/domain/IndexDetails$IndexType,indexedExpression:java/lang/String,isValid:java/lang/String,memberId:java/lang/String,memberName:java/lang/String,projectionAttributes:java/lang/String,regionName
[...]
+org/apache/geode/management/internal/cli/domain/IndexDetails,true,-2198907141534201288,fromClause:java/lang/String,indexName:java/lang/String,indexStatisticsDetails:org/apache/geode/management/internal/cli/domain/IndexDetails$IndexStatisticsDetails,indexType:org/apache/geode/management/internal/cli/domain/IndexDetails$IndexType,indexedExpression:java/lang/String,isValid:boolean,memberId:java/lang/String,memberName:java/lang/String,projectionAttributes:java/lang/String,regionName:java/lan
[...]
 org/apache/geode/management/internal/cli/domain/IndexDetails$IndexStatisticsDetails,false,numberOfKeys:java/lang/Long,numberOfUpdates:java/lang/Long,numberOfValues:java/lang/Long,totalUpdateTime:java/lang/Long,totalUses:java/lang/Long
 org/apache/geode/management/internal/cli/domain/IndexDetails$IndexType,false,description:java/lang/String
 org/apache/geode/management/internal/cli/domain/IndexInfo,true,1,indexName:java/lang/String,indexType:int,indexedExpression:java/lang/String,regionPath:java/lang/String
@@ -614,7 +613,6 @@ org/apache/geode/management/internal/configuration/functions/RecreateCacheFuncti
 org/apache/geode/management/internal/configuration/functions/UploadJarFunction,true,1
 org/apache/geode/management/internal/web/domain/QueryParameterSource,true,34131123582155,objectName:javax/management/ObjectName,queryExpression:javax/management/QueryExp
 org/apache/geode/management/internal/web/shell/MBeanAccessException,true,813768898269516238
-org/apache/geode/management/internal/web/shell/RestApiCallForCommandNotFoundException,true,6686566370779394304
 org/apache/geode/memcached/GemFireMemcachedServer$Protocol,false
 org/apache/geode/pdx/FieldType,false,defaultSerializedValue:java/nio/ByteBuffer,defaultValue:java/lang/Object,isFixedWidth:boolean,name:java/lang/String,width:int
 org/apache/geode/pdx/JSONFormatter$states,false
@@ -819,4 +817,4 @@ org/apache/geode/redis/internal/executor/list/ListExecutor$ListDirection,false
 org/apache/geode/security/AuthenticationFailedException,true,-8202866472279088879
 org/apache/geode/security/AuthenticationRequiredException,true,4675976651103154919
 org/apache/geode/security/GemFireSecurityException,true,3814254578203076926,cause:java/lang/Throwable
-org/apache/geode/security/NotAuthorizedException,true,419215768216387745,principal:java/security/Principal
\ No newline at end of file
+org/apache/geode/security/NotAuthorizedException,true,419215768216387745,principal:java/security/Principal
diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java
b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java
index aae902d..08be1d5 100644
--- a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java
+++ b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java
@@ -29,10 +29,9 @@ import org.apache.geode.test.junit.runners.SuiteRunner;
 @Suite.SuiteClasses({ChangeLogLevelCommandDUnitTest.class, DeployWithGroupsDUnitTest.class,
     DiskStoreCommandsDUnitTest.class, GcCommandDUnitTest.class, GemfireDataCommandsDUnitTest.class,
     GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest.class,
-    ListAndDescribeDiskStoreCommandsDUnitTest.class, ListIndexCommandDUnitTest.class,
-    ShutdownCommandDUnitTest.class, QueueCommandsDUnitTest.class, ShellCommandsDUnitTest.class,
-    ShowDeadlockDUnitTest.class, ShowLogCommandDUnitTest.class, ShowMetricsDUnitTest.class,
-    ShowStackTraceDUnitTest.class})
+    ListAndDescribeDiskStoreCommandsDUnitTest.class, ShutdownCommandDUnitTest.class,
+    QueueCommandsDUnitTest.class, ShellCommandsDUnitTest.class, ShowDeadlockDUnitTest.class,
+    ShowLogCommandDUnitTest.class, ShowMetricsDUnitTest.class, ShowStackTraceDUnitTest.class})
 public class CommandOverHttpDUnitTest {
   @ClassRule
   public static ProvideSystemProperty provideSystemProperty =
diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandOverHttpDUnitTest.java
b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandOverHttpDUnitTest.java
new file mode 100644
index 0000000..bf11933
--- /dev/null
+++ b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandOverHttpDUnitTest.java
@@ -0,0 +1,29 @@
+/*
+ * 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 org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.rules.GfshShellConnectionRule;
+import org.junit.experimental.categories.Category;
+
+@Category(DistributedTest.class)
+public class ListIndexCommandOverHttpDUnitTest extends ListIndexCommandDUnitTest {
+  @Override
+  public void connectGfsh(MemberVM vm) throws Exception {
+    gfsh.connectAndVerify(vm.getHttpPort(), GfshShellConnectionRule.PortType.http);
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <commits@geode.apache.org>'].

Mime
View raw message