ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [09/11] ignite git commit: IGNITE-3202: Tests for chained mapper.
Date Mon, 30 May 2016 16:05:19 GMT
IGNITE-3202: Tests for chained mapper.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1ce0ac82
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1ce0ac82
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1ce0ac82

Branch: refs/heads/ignite-3202
Commit: 1ce0ac826a245dfdcd20ca9894db8c1b96596bec
Parents: 2394831
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Mon May 30 16:56:31 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Mon May 30 16:56:31 2016 +0300

----------------------------------------------------------------------
 .../util/ChainedUserNameMapperSelfTest.java     | 92 ++++++++++++++++++++
 .../testsuites/IgniteHadoopTestSuite.java       |  5 +-
 2 files changed, 96 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/1ce0ac82/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/ChainedUserNameMapperSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/ChainedUserNameMapperSelfTest.java
b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/ChainedUserNameMapperSelfTest.java
new file mode 100644
index 0000000..d134ad8
--- /dev/null
+++ b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/ChainedUserNameMapperSelfTest.java
@@ -0,0 +1,92 @@
+package org.apache.ignite.hadoop.util;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.igfs.IgfsUserContext;
+import org.apache.ignite.internal.processors.igfs.IgfsUtils;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+
+/**
+ * Tests for chained user name mapper.
+ */
+public class ChainedUserNameMapperSelfTest extends GridCommonAbstractTest {
+    /** Test instance. */
+    private static final String INSTANCE = "test_instance";
+
+    /** Test realm. */
+    private static final String REALM = "test_realm";
+
+    /**
+     * Test case when mappers are null.
+     *
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+    public void testNullMappers() throws Exception {
+        GridTestUtils.assertThrows(null, new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                create((UserNameMapper[])null);
+
+                return null;
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test case when one of mappers is null.
+     *
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+    public void testNullMapperElement() throws Exception {
+        GridTestUtils.assertThrows(null, new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                create(new BasicUserNameMapper(), null);
+
+                return null;
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test actual chaining logic.
+     *
+     * @throws Exception If failed.
+     */
+    public void testChaining() throws Exception {
+        BasicUserNameMapper mapper1 = new BasicUserNameMapper();
+
+        mapper1.setMappings(Collections.singletonMap("1", "101"));
+
+        KerberosUserNameMapper mapper2 = new KerberosUserNameMapper();
+
+        mapper2.setInstance(INSTANCE);
+        mapper2.setRealm(REALM);
+
+        ChainedUserNameMapper mapper = create(mapper1, mapper2);
+
+        assertEquals("101" + "/" + INSTANCE + "@" + REALM, mapper.map("1"));
+        assertEquals("2" + "/" + INSTANCE + "@" + REALM, mapper.map("2"));
+        assertEquals(IgfsUtils.fixUserName(null) + "/" + INSTANCE + "@" + REALM, mapper.map(null));
+    }
+
+    /**
+     * Create chained mapper.
+     *
+     * @param mappers Child mappers.
+     * @return Chained mapper.
+     */
+    private ChainedUserNameMapper create(UserNameMapper... mappers) {
+        ChainedUserNameMapper mapper = new ChainedUserNameMapper();
+
+        mapper.setMappers(mappers);
+
+        mapper.start();
+
+        return mapper;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1ce0ac82/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
b/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
index f7c5691..e0d1142 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
@@ -27,7 +27,9 @@ import org.apache.ignite.client.hadoop.HadoopClientProtocolSelfTest;
 import org.apache.ignite.hadoop.cache.HadoopTxConfigCacheTest;
 import org.apache.ignite.hadoop.fs.KerberosHadoopFileSystemFactorySelfTest;
 import org.apache.ignite.hadoop.util.BasicUserNameMapperSelfTest;
+import org.apache.ignite.hadoop.util.ChainedUserNameMapperSelfTest;
 import org.apache.ignite.hadoop.util.KerberosUserNameMapper;
+import org.apache.ignite.hadoop.util.KerberosUserNameMapperSelfTest;
 import org.apache.ignite.igfs.Hadoop1OverIgfsDualAsyncTest;
 import org.apache.ignite.igfs.Hadoop1OverIgfsDualSyncTest;
 import org.apache.ignite.igfs.HadoopFIleSystemFactorySelfTest;
@@ -107,7 +109,8 @@ public class IgniteHadoopTestSuite extends TestSuite {
         TestSuite suite = new TestSuite("Ignite Hadoop MR Test Suite");
 
         suite.addTest(new TestSuite(ldr.loadClass(BasicUserNameMapperSelfTest.class.getName())));
-        suite.addTest(new TestSuite(ldr.loadClass(KerberosUserNameMapper.class.getName())));
+        suite.addTest(new TestSuite(ldr.loadClass(KerberosUserNameMapperSelfTest.class.getName())));
+        suite.addTest(new TestSuite(ldr.loadClass(ChainedUserNameMapperSelfTest.class.getName())));
 
         suite.addTest(new TestSuite(ldr.loadClass(KerberosHadoopFileSystemFactorySelfTest.class.getName())));
 


Mime
View raw message