Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2453C18A68 for ; Wed, 8 Jul 2015 10:08:51 +0000 (UTC) Received: (qmail 43635 invoked by uid 500); 8 Jul 2015 10:08:51 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 43606 invoked by uid 500); 8 Jul 2015 10:08:51 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 43597 invoked by uid 99); 8 Jul 2015 10:08:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Jul 2015 10:08:51 +0000 X-ASF-Spam-Status: No, hits=-2000.6 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 08 Jul 2015 10:06:31 +0000 Received: (qmail 41398 invoked by uid 99); 8 Jul 2015 10:08:15 -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; Wed, 08 Jul 2015 10:08:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CFE47DFDE6; Wed, 8 Jul 2015 10:08:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ntikhonov@apache.org To: commits@ignite.incubator.apache.org Date: Wed, 08 Jul 2015 10:08:50 -0000 Message-Id: <9f23144e83b84b7882da607ede60f255@git.apache.org> In-Reply-To: <6cc074db06024c3ea8643d6b84e610a4@git.apache.org> References: <6cc074db06024c3ea8643d6b84e610a4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [36/50] incubator-ignite git commit: #ignite-1101: Add test for cache future runtime exception. X-Virus-Checked: Checked by ClamAV on apache.org #ignite-1101: Add test for cache future runtime exception. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/8c1ba5af Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/8c1ba5af Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/8c1ba5af Branch: refs/heads/ignite-950 Commit: 8c1ba5afe37d1e9f38d99738874046076556915f Parents: 96c9695 Author: ivasilinets Authored: Tue Jul 7 13:40:11 2015 +0300 Committer: ivasilinets Committed: Tue Jul 7 13:40:11 2015 +0300 ---------------------------------------------------------------------- .../cache/CacheFutureExceptionSelfTest.java | 171 +++++++++++++++++++ .../ignite/testsuites/IgniteCacheTestSuite.java | 1 + 2 files changed, 172 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8c1ba5af/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheFutureExceptionSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheFutureExceptionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheFutureExceptionSelfTest.java new file mode 100644 index 0000000..27bfe17 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheFutureExceptionSelfTest.java @@ -0,0 +1,171 @@ +/* + * 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; + +import org.apache.ignite.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.util.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.testframework.junits.common.*; + +import javax.cache.*; +import java.io.*; +import java.util.*; +import java.util.concurrent.*; + +import static java.util.concurrent.TimeUnit.*; + +/** + * Cache future self test. + */ +public class CacheFutureExceptionSelfTest extends GridCommonAbstractTest { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = StartNode.createConfiguration(); + + cfg.setClientMode(true); + + return cfg; + } + + /** + * @throws Exception If failed. + */ + public void testAsyncCacheFuture() throws Exception { + final CountDownLatch readyLatch = new CountDownLatch(1); + + GridJavaProcess node1 = null; + + Collection jvmArgs = Arrays.asList("-ea", "-DIGNITE_QUIET=false"); + + try { + node1 = GridJavaProcess.exec( + StartNode.class.getName(), null, + log, + new CI1() { + @Override public void apply(String s) { + info("Server node1: " + s); + + if (s.contains("Topology snapshot")) + readyLatch.countDown(); + } + }, + null, + jvmArgs, + null + ); + + assertTrue(readyLatch.await(60, SECONDS)); + + Ignite client = startGrid(0); + + IgniteCache cache = client.getOrCreateCache("CACHE"); + + cache.put("key", new NotSerializableClass()); + + System.setProperty("FAIL", "true"); + + IgniteCache asyncCache = cache.withAsync(); + + asyncCache.get("key"); + + final CountDownLatch futLatch = new CountDownLatch(1); + + asyncCache.future().listen(new IgniteInClosure>() { + @Override public void apply(IgniteFuture fut) { + assertTrue(fut.isDone()); + + try { + fut.get(); + + fail(); + } + catch (CacheException e) { + log.info("Expected error: " + e); + + futLatch.countDown(); + } + } + }); + + assertTrue(futLatch.await(60, SECONDS)); + } + finally { + if (node1 != null) + node1.killProcess(); + } + } + + /** + * Test class. + */ + private static class NotSerializableClass implements Serializable { + /** {@inheritDoc}*/ + private void writeObject(ObjectOutputStream out) throws IOException { + out.writeObject(this); + } + + /** {@inheritDoc}*/ + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + if (System.getProperty("FAIL") != null) + throw new RuntimeException("Deserialization failed."); + + in.readObject(); + } + } + + /** + * Test class. + */ + public static class StartNode { + /** + * @return Configuration. + */ + public static IgniteConfiguration createConfiguration() { + IgniteConfiguration cfg = new IgniteConfiguration(); + + cfg.setPeerClassLoadingEnabled(true); + + cfg.setLocalHost("127.0.0.1"); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinderCleanFrequency(1000); + + TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(); + + ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500..47509")); + + disco.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(disco); + + return cfg; + } + + /** + * @param args Main parameters. + */ + public static void main(String[] args) { + Ignition.start(createConfiguration()); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8c1ba5af/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java index 0a31f49..39702a3 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java @@ -132,6 +132,7 @@ public class IgniteCacheTestSuite extends TestSuite { suite.addTestSuite(GridCacheObjectToStringSelfTest.class); suite.addTestSuite(GridCacheLoadOnlyStoreAdapterSelfTest.class); suite.addTestSuite(GridCacheGetStoreErrorSelfTest.class); + suite.addTestSuite(CacheFutureExceptionSelfTest.class); suite.addTestSuite(GridCacheAsyncOperationsLimitSelfTest.class); suite.addTestSuite(GridCacheTtlManagerSelfTest.class); suite.addTestSuite(GridCacheLifecycleAwareSelfTest.class);