ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [2/3] ignite git commit: IGNITE-2206: Tests refactoring.
Date Mon, 04 Jan 2016 17:31:40 GMT
IGNITE-2206: Tests refactoring.


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

Branch: refs/heads/ignite-2206
Commit: 4269e29f42459e7f29e92c8999b86bee69e8f58a
Parents: 2e334f4
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Mon Jan 4 19:27:49 2016 +0400
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Mon Jan 4 19:27:49 2016 +0400

----------------------------------------------------------------------
 .../processors/igfs/IgfsAbstractSelfTest.java   |  8 +--
 .../igfs/IgfsExUniversalFileSystemAdapter.java  |  2 +-
 .../igfs/UniversalFileSystemAdapter.java        |  5 +-
 .../ignite/igfs/Hadoop1DualAbstractTest.java    | 14 +++---
 ...oopFileSystemUniversalFileSystemAdapter.java | 52 ++++++++++++--------
 5 files changed, 47 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4269e29f/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java
index b290303..015b992 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java
@@ -2744,7 +2744,7 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest
{
         finally {
             U.closeQuiet(os);
 
-            IgfsEx igfsEx = uni.getAdapter(IgfsEx.class);
+            IgfsEx igfsEx = uni.unwrap(IgfsEx.class);
 
             if (igfsEx != null)
                 awaitFileClose(igfsEx.asSecondary(), file);
@@ -2868,7 +2868,7 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest
{
      * @throws IgniteCheckedException If failed.
      */
     protected void checkExist(UniversalFileSystemAdapter uni, IgfsPath... paths) throws IgniteCheckedException
{
-        IgfsEx ex = uni.getAdapter(IgfsEx.class);
+        IgfsEx ex = uni.unwrap(IgfsEx.class);
         for (IgfsPath path : paths) {
             if (ex != null)
                 assert ex.context().meta().fileId(path) != null : "Path doesn't exist [igfs="
+ ex.name() +
@@ -2921,7 +2921,7 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest
{
      * @throws Exception If failed.
      */
     protected void checkNotExist(UniversalFileSystemAdapter uni, IgfsPath... paths) throws
Exception {
-        IgfsEx ex = uni.getAdapter(IgfsEx.class);
+        IgfsEx ex = uni.unwrap(IgfsEx.class);
         for (IgfsPath path : paths) {
             if (ex != null)
                 assert ex.context().meta().fileId(path) == null : "Path exists [igfs=" +
ex.name() + ", path=" +
@@ -3222,7 +3222,7 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest
{
      */
     @SuppressWarnings("unchecked")
     public static void clear(UniversalFileSystemAdapter uni) throws Exception {
-        IgfsEx igfsEx = uni.getAdapter(IgfsEx.class);
+        IgfsEx igfsEx = uni.unwrap(IgfsEx.class);
 
         if (igfsEx != null)
             clear(igfsEx);

http://git-wip-us.apache.org/repos/asf/ignite/blob/4269e29f/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsExUniversalFileSystemAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsExUniversalFileSystemAdapter.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsExUniversalFileSystemAdapter.java
index a6fb4d8..c6bef72 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsExUniversalFileSystemAdapter.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsExUniversalFileSystemAdapter.java
@@ -92,7 +92,7 @@ public class IgfsExUniversalFileSystemAdapter implements UniversalFileSystemAdap
     }
 
     /** {@inheritDoc} */
-    @Override public <T> T getAdapter(Class<T> clazz) {
+    @Override public <T> T unwrap(Class<T> clazz) {
         if (clazz == IgfsEx.class)
             return (T)igfsEx;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/4269e29f/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/UniversalFileSystemAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/UniversalFileSystemAdapter.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/UniversalFileSystemAdapter.java
index ba8c164..eef0057 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/UniversalFileSystemAdapter.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/UniversalFileSystemAdapter.java
@@ -31,8 +31,9 @@ public interface UniversalFileSystemAdapter {
     /**
      * Gets name of the FS.
      * @return name of this file system.
+     * @throws IOException in case of failure.
      */
-    String name();
+    String name() throws IOException;
 
     /**
      * Answers if a file denoted by path exists.
@@ -93,5 +94,5 @@ public interface UniversalFileSystemAdapter {
      * @param <T> The type we need to adapt to.
      * @return the adapter object of the given type.
      */
-    <T> T getAdapter(Class<T> clazz);
+    <T> T unwrap(Class<T> clazz);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/4269e29f/modules/hadoop/src/test/java/org/apache/ignite/igfs/Hadoop1DualAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/igfs/Hadoop1DualAbstractTest.java
b/modules/hadoop/src/test/java/org/apache/ignite/igfs/Hadoop1DualAbstractTest.java
index 24ef3b0..10b1bcd 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/igfs/Hadoop1DualAbstractTest.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/igfs/Hadoop1DualAbstractTest.java
@@ -19,7 +19,7 @@ package org.apache.ignite.igfs;
 
 import java.io.IOException;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FileSystem;
+import org.apache.ignite.hadoop.fs.CachingHadoopFileSystemFactory;
 import org.apache.ignite.hadoop.fs.IgniteHadoopIgfsSecondaryFileSystem;
 import org.apache.ignite.igfs.secondary.IgfsSecondaryFileSystem;
 import org.apache.ignite.internal.processors.igfs.IgfsDualAbstractSelfTest;
@@ -74,14 +74,16 @@ public abstract class Hadoop1DualAbstractTest extends IgfsDualAbstractSelfTest
{
 
         prepareConfiguration();
 
-        IgniteHadoopIgfsSecondaryFileSystem second =
-            new IgniteHadoopIgfsSecondaryFileSystem(secondaryUri, secondaryConfFullPath);
+        CachingHadoopFileSystemFactory factory = new CachingHadoopFileSystemFactory();
 
-        second.start();
+        factory.setUri(secondaryUri);
+        factory.setConfigPaths(secondaryConfFullPath);
 
-        FileSystem fileSystem = second.fileSystem();
+        IgniteHadoopIgfsSecondaryFileSystem second = new IgniteHadoopIgfsSecondaryFileSystem();
 
-        igfsSecondary = new HadoopFileSystemUniversalFileSystemAdapter(fileSystem);
+        second.setFileSystemFactory(factory);
+
+        igfsSecondary = new HadoopFileSystemUniversalFileSystemAdapter(factory);
 
         return second;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/4269e29f/modules/hadoop/src/test/java/org/apache/ignite/igfs/HadoopFileSystemUniversalFileSystemAdapter.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/igfs/HadoopFileSystemUniversalFileSystemAdapter.java
b/modules/hadoop/src/test/java/org/apache/ignite/igfs/HadoopFileSystemUniversalFileSystemAdapter.java
index 640aef6..5b6fd81 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/igfs/HadoopFileSystemUniversalFileSystemAdapter.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/igfs/HadoopFileSystemUniversalFileSystemAdapter.java
@@ -26,6 +26,8 @@ import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.permission.FsPermission;
+import org.apache.ignite.configuration.FileSystemConfiguration;
+import org.apache.ignite.hadoop.fs.HadoopFileSystemFactory;
 import org.apache.ignite.internal.processors.hadoop.igfs.HadoopIgfsUtils;
 import org.apache.ignite.internal.processors.igfs.IgfsEx;
 import org.apache.ignite.internal.processors.igfs.UniversalFileSystemAdapter;
@@ -34,57 +36,55 @@ import org.apache.ignite.internal.processors.igfs.UniversalFileSystemAdapter;
  * Universal adapter wrapping {@link org.apache.hadoop.fs.FileSystem} instance.
  */
 public class HadoopFileSystemUniversalFileSystemAdapter implements UniversalFileSystemAdapter
{
-    /** The wrapped filesystem. */
-    private final FileSystem fileSys;
+    /** File system factory. */
+    private final HadoopFileSystemFactory factory;
 
     /**
      * Constructor.
-     * @param fs the filesystem to be wrapped.
+     * @param factory File system factory.
      */
-    public HadoopFileSystemUniversalFileSystemAdapter(FileSystem fs) {
-        assert fs != null;
+    public HadoopFileSystemUniversalFileSystemAdapter(HadoopFileSystemFactory factory) {
+        assert factory != null;
 
-        this.fileSys = fs;
+        this.factory = factory;
     }
 
     /** {@inheritDoc} */
-    @Override public String name() {
-        return fileSys.getUri().toString();
+    @Override public String name() throws IOException {
+        return get().getUri().toString();
     }
 
     /** {@inheritDoc} */
     @Override public boolean exists(String path) throws IOException {
-        return fileSys.exists(new Path(path));
+        return get().exists(new Path(path));
     }
 
     /** {@inheritDoc} */
     @Override public boolean delete(String path, boolean recursive) throws IOException {
-        boolean ok = fileSys.delete(new Path(path), recursive);
-        return ok;
+        return get().delete(new Path(path), recursive);
     }
 
     /** {@inheritDoc} */
     @Override public void mkdirs(String path) throws IOException {
-        boolean ok = fileSys.mkdirs(new Path(path));
+        boolean ok = get().mkdirs(new Path(path));
         if (!ok)
             throw new IOException("Failed to mkdirs: " + path);
     }
 
     /** {@inheritDoc} */
     @Override public void format() throws IOException {
-        HadoopIgfsUtils.clear(fileSys);
+        HadoopIgfsUtils.clear(get());
     }
 
     /** {@inheritDoc} */
     @Override public Map<String, String> properties(String path) throws IOException
{
         Path p = new Path(path);
 
-        FileStatus status = fileSys.getFileStatus(p);
+        FileStatus status = get().getFileStatus(p);
 
         Map<String,String> m = new HashMap<>(3); // max size == 4
 
         m.put(IgfsEx.PROP_USER_NAME, status.getOwner());
-
         m.put(IgfsEx.PROP_GROUP_NAME, status.getGroup());
 
         FsPermission perm = status.getPermission();
@@ -97,7 +97,7 @@ public class HadoopFileSystemUniversalFileSystemAdapter implements UniversalFile
 
     /** {@inheritDoc} */
     @Override public InputStream openInputStream(String path) throws IOException {
-        return fileSys.open(new Path(path));
+        return get().open(new Path(path));
     }
 
     /** {@inheritDoc} */
@@ -105,17 +105,27 @@ public class HadoopFileSystemUniversalFileSystemAdapter implements UniversalFile
         Path p = new Path(path);
 
         if (append)
-            return fileSys.append(p);
+            return get().append(p);
         else
-            return fileSys.create(p, true/*overwrite*/);
+            return get().create(p, true/*overwrite*/);
     }
 
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
-    @Override public <T> T getAdapter(Class<T> clazz) {
-        if (clazz == FileSystem.class)
-            return (T)fileSys;
+    @Override public <T> T unwrap(Class<T> cls) {
+        if (HadoopFileSystemFactory.class.isAssignableFrom(cls))
+            return (T)factory;
 
         return null;
     }
+
+    /**
+     * Create file system.
+     *
+     * @return File system.
+     * @throws IOException If failed.
+     */
+    private FileSystem get() throws IOException {
+        return factory.get(FileSystemConfiguration.DFLT_USER_NAME);
+    }
 }
\ No newline at end of file


Mime
View raw message