You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vk...@apache.org on 2015/03/04 02:31:39 UTC
[09/50] [abbrv] incubator-ignite git commit: Fixed cache metrics
tests.
Fixed cache metrics tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/bd28d7db
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/bd28d7db
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/bd28d7db
Branch: refs/heads/master
Commit: bd28d7db79839ff10f6998e8a5eef4e8056c31ef
Parents: f459714
Author: nikolay_tikhonov <nt...@gridgain.com>
Authored: Mon Feb 16 14:47:15 2015 +0300
Committer: nikolay_tikhonov <nt...@gridgain.com>
Committed: Mon Feb 16 14:48:58 2015 +0300
----------------------------------------------------------------------
.../near/GridCacheNearMetricsSelfTest.java | 4 +-
...idCachePartitionedHitsAndMissesSelfTest.java | 177 +++++++++++++++++++
.../IgniteCacheMetricsSelfTestSuite.java | 21 +--
...idCachePartitionedHitsAndMissesSelfTest.java | 176 ------------------
.../IgniteH2IndexingSpiTestSuite.java | 2 -
5 files changed, 190 insertions(+), 190 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28d7db/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearMetricsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearMetricsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearMetricsSelfTest.java
index 0086311..2c52928 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearMetricsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearMetricsSelfTest.java
@@ -108,7 +108,7 @@ public class GridCacheNearMetricsSelfTest extends GridCacheAbstractSelfTest {
// Put and get a few keys.
for (int i = 0; ; i++) {
if (affinity(cache0).isPrimary(g0.cluster().localNode(), i)) {
- cache0.put(i, i); // +1 read
+ cache0.getAndPut(i, i); // +1 read
cache0.get(i); // +1 read.
@@ -140,7 +140,7 @@ public class GridCacheNearMetricsSelfTest extends GridCacheAbstractSelfTest {
if (affinity(jcache).isPrimary(g.cluster().localNode(), key)) {
assertEquals(2, jcache.metrics().getCacheGets());
assertEquals(1, jcache.metrics().getCacheHits());
- assertEquals(1, jcache.metrics().getCacheHits());
+ assertEquals(1, jcache.metrics().getCacheMisses());
}
else {
assertEquals(0, jcache.metrics().getCacheGets());
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28d7db/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java
new file mode 100644
index 0000000..d3464ea
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java
@@ -0,0 +1,177 @@
+/*
+ * 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.ignite.internal.processors.cache.distributed.near;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.marshaller.optimized.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.apache.ignite.transactions.*;
+
+import javax.cache.processor.*;
+import java.util.*;
+
+import static org.apache.ignite.cache.CacheDistributionMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
+
+/**
+ * Test for issue GG-3997 Total Hits and Misses display wrong value for in-memory database.
+ */
+public class GridCachePartitionedHitsAndMissesSelfTest extends GridCommonAbstractTest {
+ /** Amount of grids to start. */
+ private static final int GRID_CNT = 3;
+
+ /** Count of total numbers to generate. */
+ private static final int CNT = 2000;
+
+ /** IP Finder. */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setMarshaller(new OptimizedMarshaller(false));
+
+ // DiscoverySpi
+ TcpDiscoverySpi disco = new TcpDiscoverySpi();
+ disco.setIpFinder(IP_FINDER);
+ cfg.setDiscoverySpi(disco);
+
+ // Cache.
+ cfg.setCacheConfiguration(cacheConfiguration(gridName));
+
+ TransactionConfiguration tCfg = new TransactionConfiguration();
+
+ tCfg.setDefaultTxConcurrency(TransactionConcurrency.PESSIMISTIC);
+ tCfg.setDefaultTxIsolation(TransactionIsolation.REPEATABLE_READ);
+
+ cfg.setTransactionConfiguration(tCfg);
+
+ return cfg;
+ }
+
+ /**
+ * Cache configuration.
+ *
+ * @param gridName Grid name.
+ * @return Cache configuration.
+ * @throws Exception In case of error.
+ */
+ protected CacheConfiguration cacheConfiguration(String gridName) throws Exception {
+ CacheConfiguration cfg = defaultCacheConfiguration();
+ cfg.setCacheMode(PARTITIONED);
+ cfg.setStartSize(700000);
+ cfg.setWriteSynchronizationMode(FULL_ASYNC);
+ cfg.setEvictionPolicy(null);
+ cfg.setBackups(1);
+ cfg.setDistributionMode(PARTITIONED_ONLY);
+ cfg.setPreloadPartitionedDelay(-1);
+ cfg.setBackups(1);
+ cfg.setStatisticsEnabled(true);
+
+ CacheQueryConfiguration qcfg = new CacheQueryConfiguration();
+
+ qcfg.setIndexPrimitiveKey(true);
+
+ cfg.setQueryConfiguration(qcfg);
+
+ return cfg;
+ }
+
+ /**
+ * This test is just a wrapper for org.apache.ignite.examples.datagrid.CachePopularNumbersExample
+ *
+ * @throws Exception If failed.
+ */
+ public void testHitsAndMisses() throws Exception {
+ assert(GRID_CNT > 0);
+
+ startGrids(GRID_CNT);
+
+ try {
+ final Ignite g = grid(0);
+
+ realTimePopulate(g);
+
+ // Check metrics for the whole cache.
+ long hits = 0;
+ long misses = 0;
+
+ for (int i = 0; i < GRID_CNT; i++) {
+ CacheMetrics m = grid(i).jcache(null).metrics();
+
+ hits += m.getCacheHits();
+ misses += m.getCacheMisses();
+ }
+
+ // Check that invoke and loader updated metrics
+ assertEquals(CNT, hits);
+ assertEquals(CNT, misses);
+ }
+ finally {
+ stopAllGrids();
+ }
+ }
+
+ /**
+ * Populates cache with data loader.
+ *
+ * @param g Grid.
+ * @throws IgniteCheckedException If failed.
+ */
+ private static void realTimePopulate(final Ignite g) throws IgniteCheckedException {
+ try (IgniteDataLoader<Integer, Long> ldr = g.dataLoader(null)) {
+ // Sets max values to 1 so cache metrics have correct values.
+ ldr.perNodeParallelLoadOperations(1);
+
+ // Count closure which increments a count on remote node.
+ ldr.updater(new IncrementingUpdater());
+
+ for (int i = 0; i < CNT; i++)
+ ldr.addData(i % (CNT / 2), 1L);
+ }
+ }
+
+ /**
+ * Increments value for key.
+ */
+ private static class IncrementingUpdater implements IgniteDataLoader.Updater<Integer, Long> {
+ /** */
+ private static final EntryProcessor<Integer, Long, Void> INC = new EntryProcessor<Integer, Long, Void>() {
+ @Override public Void process(MutableEntry<Integer, Long> e, Object... args) {
+ Long val = e.getValue();
+
+ e.setValue(val == null ? 1 : val + 1);
+
+ return null;
+ }
+ };
+
+ /** {@inheritDoc} */
+ @Override public void update(IgniteCache<Integer, Long> cache, Collection<Map.Entry<Integer, Long>> entries) {
+ for (Map.Entry<Integer, Long> entry : entries)
+ cache.invoke(entry.getKey(), INC);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28d7db/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java
index ae3fa32..511afec 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java
@@ -33,18 +33,19 @@ public class IgniteCacheMetricsSelfTestSuite extends TestSuite {
public static TestSuite suite() throws Exception {
TestSuite suite = new TestSuite("Cache Metrics Test Suite");
- suite.addTest(new TestSuite(GridCacheLocalMetricsSelfTest.class));
- suite.addTest(new TestSuite(GridCacheNearMetricsSelfTest.class));
- suite.addTest(new TestSuite(GridCacheReplicatedMetricsSelfTest.class));
- suite.addTest(new TestSuite(GridCachePartitionedMetricsSelfTest.class));
+ suite.addTestSuite(GridCacheLocalMetricsSelfTest.class);
+ suite.addTestSuite(GridCacheNearMetricsSelfTest.class);
+ suite.addTestSuite(GridCacheReplicatedMetricsSelfTest.class);
+ suite.addTestSuite(GridCachePartitionedMetricsSelfTest.class);
+ suite.addTestSuite(GridCachePartitionedHitsAndMissesSelfTest.class);
// Atomic cache.
- suite.addTest(new TestSuite(GridCacheAtomicLocalMetricsSelfTest.class));
- suite.addTest(new TestSuite(GridCacheAtomicLocalMetricsNoStoreSelfTest.class));
- suite.addTest(new TestSuite(GridCacheAtomicReplicatedMetricsSelfTest.class));
- suite.addTest(new TestSuite(GridCacheAtomicPartitionedMetricsSelfTest.class));
- suite.addTest(new TestSuite(GridCacheAtomicPartitionedTckMetricsSelfTestImpl.class));
- suite.addTest(new TestSuite(GridCacheAtomicLocalTckMetricsSelfTestImpl.class));
+ suite.addTestSuite(GridCacheAtomicLocalMetricsSelfTest.class);
+ suite.addTestSuite(GridCacheAtomicLocalMetricsNoStoreSelfTest.class);
+ suite.addTestSuite(GridCacheAtomicReplicatedMetricsSelfTest.class);
+ suite.addTestSuite(GridCacheAtomicPartitionedMetricsSelfTest.class);
+ suite.addTestSuite(GridCacheAtomicPartitionedTckMetricsSelfTestImpl.class);
+ suite.addTestSuite(GridCacheAtomicLocalTckMetricsSelfTestImpl.class);
return suite;
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28d7db/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java
deleted file mode 100644
index 11397f1..0000000
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * 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.ignite.internal.processors.cache.distributed.near;
-
-import org.apache.ignite.*;
-import org.apache.ignite.cache.*;
-import org.apache.ignite.configuration.*;
-import org.apache.ignite.marshaller.optimized.*;
-import org.apache.ignite.spi.discovery.tcp.*;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
-import org.apache.ignite.testframework.junits.common.*;
-import org.apache.ignite.transactions.*;
-
-import javax.cache.processor.*;
-import java.util.*;
-
-import static org.apache.ignite.cache.CacheDistributionMode.*;
-import static org.apache.ignite.cache.CacheMode.*;
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
-
-/**
- * Test for issue GG-3997 Total Hits and Misses display wrong value for in-memory database.
- */
-public class GridCachePartitionedHitsAndMissesSelfTest extends GridCommonAbstractTest {
- /** Amount of grids to start. */
- private static final int GRID_CNT = 3;
-
- /** Count of total numbers to generate. */
- private static final int CNT = 2000;
-
- /** IP Finder. */
- private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
- /** {@inheritDoc} */
- @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
- IgniteConfiguration cfg = super.getConfiguration(gridName);
-
- cfg.setMarshaller(new OptimizedMarshaller(false));
-
- // DiscoverySpi
- TcpDiscoverySpi disco = new TcpDiscoverySpi();
- disco.setIpFinder(IP_FINDER);
- cfg.setDiscoverySpi(disco);
-
- // Cache.
- cfg.setCacheConfiguration(cacheConfiguration(gridName));
-
- TransactionConfiguration tCfg = new TransactionConfiguration();
-
- tCfg.setDefaultTxConcurrency(TransactionConcurrency.PESSIMISTIC);
- tCfg.setDefaultTxIsolation(TransactionIsolation.REPEATABLE_READ);
-
- cfg.setTransactionConfiguration(tCfg);
-
- return cfg;
- }
-
- /**
- * Cache configuration.
- *
- * @param gridName Grid name.
- * @return Cache configuration.
- * @throws Exception In case of error.
- */
- protected CacheConfiguration cacheConfiguration(String gridName) throws Exception {
- CacheConfiguration cfg = defaultCacheConfiguration();
- cfg.setCacheMode(PARTITIONED);
- cfg.setStartSize(700000);
- cfg.setWriteSynchronizationMode(FULL_ASYNC);
- cfg.setEvictionPolicy(null);
- cfg.setBackups(1);
- cfg.setDistributionMode(PARTITIONED_ONLY);
- cfg.setPreloadPartitionedDelay(-1);
- cfg.setBackups(1);
- cfg.setStatisticsEnabled(true);
-
- CacheQueryConfiguration qcfg = new CacheQueryConfiguration();
-
- qcfg.setIndexPrimitiveKey(true);
-
- cfg.setQueryConfiguration(qcfg);
-
- return cfg;
- }
-
- /**
- * This test is just a wrapper for org.apache.ignite.examples.datagrid.CachePopularNumbersExample
- *
- * @throws Exception If failed.
- */
- public void testHitsAndMisses() throws Exception {
- assert(GRID_CNT > 0);
-
- startGrids(GRID_CNT);
-
- try {
- final Ignite g = grid(0);
-
- realTimePopulate(g);
-
- // Check metrics for the whole cache.
- long hits = 0;
- long misses = 0;
-
- for (int i = 0; i < GRID_CNT; i++) {
- CacheMetrics m = grid(i).jcache(null).metrics();
-
- hits += m.getCacheHits();
- misses += m.getCacheMisses();
- }
-
- assertEquals(CNT / 2, hits);
- assertEquals(CNT / 2, misses);
- }
- finally {
- stopAllGrids();
- }
- }
-
- /**
- * Populates cache with data loader.
- *
- * @param g Grid.
- * @throws IgniteCheckedException If failed.
- */
- private static void realTimePopulate(final Ignite g) throws IgniteCheckedException {
- try (IgniteDataLoader<Integer, Long> ldr = g.dataLoader(null)) {
- // Sets max values to 1 so cache metrics have correct values.
- ldr.perNodeParallelLoadOperations(1);
-
- // Count closure which increments a count on remote node.
- ldr.updater(new IncrementingUpdater());
-
- for (int i = 0; i < CNT; i++)
- ldr.addData(i % (CNT / 2), 1L);
- }
- }
-
- /**
- * Increments value for key.
- */
- private static class IncrementingUpdater implements IgniteDataLoader.Updater<Integer, Long> {
- /** */
- private static final EntryProcessor<Integer, Long, Void> INC = new EntryProcessor<Integer, Long, Void>() {
- @Override public Void process(MutableEntry<Integer, Long> e, Object... args) {
- Long val = e.getValue();
-
- e.setValue(val == null ? 1 : val + 1);
-
- return null;
- }
- };
-
- /** {@inheritDoc} */
- @Override public void update(IgniteCache<Integer, Long> cache, Collection<Map.Entry<Integer, Long>> entries) {
- for (Map.Entry<Integer, Long> entry : entries)
- cache.invoke(entry.getKey(), INC);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28d7db/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteH2IndexingSpiTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteH2IndexingSpiTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteH2IndexingSpiTestSuite.java
index 58f3a92..bd9cca6 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteH2IndexingSpiTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteH2IndexingSpiTestSuite.java
@@ -19,7 +19,6 @@ package org.apache.ignite.testsuites;
import junit.framework.*;
import org.apache.ignite.internal.processors.cache.*;
-import org.apache.ignite.internal.processors.cache.distributed.near.*;
import org.apache.ignite.internal.processors.query.h2.*;
import org.apache.ignite.internal.processors.query.h2.opt.*;
@@ -49,7 +48,6 @@ public class IgniteH2IndexingSpiTestSuite extends TestSuite {
// Tests moved to this suite since they require GridH2IndexingSpi.
suite.addTestSuite(GridCacheOffHeapAndSwapSelfTest.class);
suite.addTestSuite(GridIndexingWithNoopSwapSelfTest.class);
- suite.addTestSuite(GridCachePartitionedHitsAndMissesSelfTest.class);
suite.addTestSuite(GridCacheSwapSelfTest.class);
suite.addTestSuite(GridCacheOffHeapSelfTest.class);