You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2015/11/26 06:33:08 UTC

[07/10] mina-sshd git commit: Added the capability to write debug output messages from a test

Added the capability to write debug output messages from a test

* Disabled by default - can be activated via -Dorg.apache.sshd.test.outputDebugMessages=true
* Used to add information to tests that seem to fail from time to time without any obvious reason


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/88a30f56
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/88a30f56
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/88a30f56

Branch: refs/heads/master
Commit: 88a30f562aa0ded9c9ff19f37579e43e72139910
Parents: fd3cb93
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Thu Nov 26 07:26:52 2015 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Thu Nov 26 07:26:52 2015 +0200

----------------------------------------------------------------------
 .../java/org/apache/sshd/KeyReExchangeTest.java | 10 +++---
 .../org/apache/sshd/client/scp/ScpTest.java     | 17 +++++++---
 .../subsystem/sftp/SftpFileSystemTest.java      | 35 ++++++++++----------
 .../sshd/client/subsystem/sftp/SftpTest.java    |  6 ++--
 .../apache/sshd/util/test/BaseTestSupport.java  | 13 ++++++++
 5 files changed, 52 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/88a30f56/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
index f8619bb..077e531 100644
--- a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
@@ -329,8 +329,9 @@ public class KeyReExchangeTest extends BaseTestSupport {
 
                         @Override
                         public void sessionEvent(Session session, Event event) {
-                            if (event == Event.KeyEstablished) {
-                                exchanges.incrementAndGet();
+                            if (Event.KeyEstablished.equals(event)) {
+                                int count = exchanges.incrementAndGet();
+                                outputDebugMessage("Key established for %s - count=%d", session, count);
                             }
                         }
 
@@ -409,8 +410,9 @@ public class KeyReExchangeTest extends BaseTestSupport {
 
                         @Override
                         public void sessionEvent(Session session, Event event) {
-                            if (event == Event.KeyEstablished) {
-                                exchanges.incrementAndGet();
+                            if (Event.KeyEstablished.equals(event)) {
+                                int count = exchanges.incrementAndGet();
+                                outputDebugMessage("Key established for %s - count=%d", session, count);
                             }
                         }
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/88a30f56/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
index 7d6ed21..1fd8194 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
@@ -372,6 +372,7 @@ public class ScpTest extends BaseTestSupport {
 
                 String localOutPath = localOutFile.toString();
                 String remoteOutPath = Utils.resolveRelativeRemotePath(parentPath, remoteOutFile);
+                outputDebugMessage("Expect upload failure %s => %s", localOutPath, remoteOutPath);
                 try {
                     scp.upload(localOutPath, remoteOutPath);
                     fail("Expected IOException for 1st time " + remoteOutPath);
@@ -380,15 +381,20 @@ public class ScpTest extends BaseTestSupport {
                 }
 
                 assertHierarchyTargetFolderExists(remoteDir);
+                outputDebugMessage("Expect upload success %s => %s", localOutPath, remoteOutPath);
                 scp.upload(localOutPath, remoteOutPath);
                 assertFileLength(remoteOutFile, data.length(), TimeUnit.SECONDS.toMillis(5L));
 
                 Path secondLocal = localDir.resolve(localOutFile.getFileName());
-                scp.download(remoteOutPath, Utils.resolveRelativeRemotePath(parentPath, secondLocal));
+                String downloadTarget = Utils.resolveRelativeRemotePath(parentPath, secondLocal);
+                outputDebugMessage("Expect download success %s => %s", remoteOutPath, downloadTarget);
+                scp.download(remoteOutPath, downloadTarget);
                 assertFileLength(secondLocal, data.length(), TimeUnit.SECONDS.toMillis(5L));
 
                 Path localPath = localDir.resolve("file-path.txt");
-                scp.download(remoteOutPath, Utils.resolveRelativeRemotePath(parentPath, localPath));
+                downloadTarget = Utils.resolveRelativeRemotePath(parentPath, localPath);
+                outputDebugMessage("Expect download success %s => %s", remoteOutPath, downloadTarget);
+                scp.download(remoteOutPath, downloadTarget);
                 assertFileLength(localPath, data.length(), TimeUnit.SECONDS.toMillis(5L));
             } finally {
                 client.stop();
@@ -795,9 +801,10 @@ public class ScpTest extends BaseTestSupport {
         final Connection conn = new Connection(TEST_LOCALHOST, port);
         try {
             ConnectionInfo info = conn.connect(null, (int) TimeUnit.SECONDS.toMillis(5L), (int) TimeUnit.SECONDS.toMillis(11L));
-            System.out.println("Connected: kex=" + info.keyExchangeAlgorithm + ", key-type=" + info.serverHostKeyAlgorithm
-                    + ", c2senc=" + info.clientToServerCryptoAlgorithm + ", s2cenc=" + info.serverToClientCryptoAlgorithm
-                    + ", c2mac=" + info.clientToServerMACAlgorithm + ", s2cmac=" + info.serverToClientMACAlgorithm);
+            outputDebugMessage("Connected: kex=%s, key-type=%s, c2senc=%s, s2cenc=%s, c2mac=%s, s2cmac=%s",
+                    info.keyExchangeAlgorithm, info.serverHostKeyAlgorithm,
+                    info.clientToServerCryptoAlgorithm, info.serverToClientCryptoAlgorithm,
+                    info.clientToServerMACAlgorithm, info.serverToClientMACAlgorithm);
             conn.authenticateWithPassword(getCurrentTestName(), getCurrentTestName());
 
             final SCPClient scp_client = new SCPClient(conn);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/88a30f56/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
index b41841c..cb00f99 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
@@ -231,7 +231,7 @@ public class SftpFileSystemTest extends BaseTestSupport {
 
                     SftpFileSystem actual = provider.getFileSystem(id);
                     assertSame("Mismatched cached instances for " + id, expected, actual);
-                    System.out.println("Created file system id: " + id);
+                    outputDebugMessage("Created file system id: %s", id);
                 }
 
                 for (SftpFileSystem fs : fsList) {
@@ -316,7 +316,7 @@ public class SftpFileSystemTest extends BaseTestSupport {
                     String name = child.getFileName().toString();
                     assertNotEquals("Unexpected dot name", ".", name);
                     assertNotEquals("Unexpected dotdot name", "..", name);
-                    System.out.append('\t').append('[').append(rootName).append("] ").println(child);
+                    outputDebugMessage("[%s] %s", rootName, child);
                 }
             } catch (IOException | RuntimeException e) {
                 // TODO on Windows one might get share problems for *.sys files
@@ -335,7 +335,7 @@ public class SftpFileSystemTest extends BaseTestSupport {
         Utils.deleteRecursive(lclSftp);
 
         Path current = fs.getPath(".").toRealPath().normalize();
-        System.out.append("CWD: ").println(current);
+        outputDebugMessage("CWD: %s", current);
 
         Path parentPath = targetPath.getParent();
         Path clientFolder = lclSftp.resolve("client");
@@ -345,20 +345,24 @@ public class SftpFileSystemTest extends BaseTestSupport {
 
         String expected = "Hello world: " + getCurrentTestName();
         {
+            outputDebugMessage("Write initial data to %s", file1);
             Files.write(file1, expected.getBytes(StandardCharsets.UTF_8));
             String buf = new String(Files.readAllBytes(file1), StandardCharsets.UTF_8);
             assertEquals("Mismatched read test data", expected, buf);
         }
 
         if (version >= SftpConstants.SFTP_V4) {
+            outputDebugMessage("getFileAttributeView(%s)", file1);
             AclFileAttributeView aclView = Files.getFileAttributeView(file1, AclFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
             assertNotNull("No ACL view for " + file1, aclView);
 
             Map<String, ?> attrs = Files.readAttributes(file1, "acl:*", LinkOption.NOFOLLOW_LINKS);
+            outputDebugMessage("readAttributes(%s) %s", file1, attrs);
             assertEquals("Mismatched owner for " + file1, aclView.getOwner(), attrs.get("owner"));
 
             @SuppressWarnings("unchecked")
             List<AclEntry> acl = (List<AclEntry>) attrs.get("acl");
+            outputDebugMessage("acls(%s) %s", file1, acl);
             assertListEquals("Mismatched ACLs for " + file1, aclView.getAcl(), acl);
         }
 
@@ -367,6 +371,7 @@ public class SftpFileSystemTest extends BaseTestSupport {
         String remFile3Path = Utils.resolveRelativeRemotePath(parentPath, clientFolder.resolve("file-3.txt"));
         Path file3 = fs.getPath(remFile3Path);
         try {
+            outputDebugMessage("Move with failure expected %s => %s", file2, file3);
             Files.move(file2, file3, LinkOption.NOFOLLOW_LINKS);
             fail("Unexpected success in moving " + file2 + " => " + file3);
         } catch (NoSuchFileException e) {
@@ -375,48 +380,44 @@ public class SftpFileSystemTest extends BaseTestSupport {
 
         Files.write(file2, "h".getBytes(StandardCharsets.UTF_8));
         try {
+            outputDebugMessage("Move with failure expected %s => %s", file1, file2);
             Files.move(file1, file2, LinkOption.NOFOLLOW_LINKS);
             fail("Unexpected success in moving " + file1 + " => " + file2);
         } catch (FileAlreadyExistsException e) {
             // expected
         }
-        System.out.append('\t').append("Move ").append(file1.toString()).append(" => ").println(file2);
+
+        outputDebugMessage("Move with success expected %s => %s", file1, file2);
         Files.move(file1, file2, LinkOption.NOFOLLOW_LINKS, StandardCopyOption.REPLACE_EXISTING);
-        System.out.append('\t').append("Move ").append(file2.toString()).append(" => ").println(file1);
+        outputDebugMessage("Move with success expected %s => %s", file2, file1);
         Files.move(file2, file1, LinkOption.NOFOLLOW_LINKS);
 
         Map<String, Object> attrs = Files.readAttributes(file1, "*");
-        System.out.append('\t').append(file1.toString()).append(" attributes: ").println(attrs);
-
-        // TODO: symbolic links only work for absolute files
-//        Path link = fs.getPath("target/sftp/client/test2.txt");
-//        Files.createSymbolicLink(link, link.relativize(file));
-//        assertTrue(Files.isSymbolicLink(link));
-//        assertEquals("test.txt", Files.readSymbolicLink(link).toString());
+        outputDebugMessage("%s attributes: %s", file1, attrs);
 
         // TODO there are many issues with symbolic links on Windows
         if (OsUtils.isUNIX()) {
             Path link = fs.getPath(remFile2Path);
             Path linkParent = link.getParent();
             Path relPath = linkParent.relativize(file1);
-            System.out.append('\t').append("Create symlink ").append(link.toString()).append(" => ").println(relPath);
+            outputDebugMessage("Create symlink %s => %s", link, relPath);
             Files.createSymbolicLink(link, relPath);
             assertTrue("Not a symbolic link: " + link, Files.isSymbolicLink(link));
 
             Path symLink = Files.readSymbolicLink(link);
             assertEquals("mismatched symbolic link name", relPath.toString(), symLink.toString());
-            System.out.append('\t').append("Delete symlink ").println(link);
+
+            outputDebugMessage("Delete symlink %s", link);
             Files.delete(link);
         }
 
         attrs = Files.readAttributes(file1, "*", LinkOption.NOFOLLOW_LINKS);
-        System.out.append('\t').append(file1.toString()).append(" no-follow attributes: ").println(attrs);
-
+        outputDebugMessage("%s no-follow attributes: %s", file1, attrs);
         assertEquals("Mismatched symlink data", expected, new String(Files.readAllBytes(file1)));
 
         try (FileChannel channel = FileChannel.open(file1)) {
             try (FileLock lock = channel.lock()) {
-                System.out.append('\t').append("Lock ").append(file1.toString()).append(": ").println(lock.toString());
+                outputDebugMessage("Lock %s: %s", file1, lock);
 
                 try (FileChannel channel2 = FileChannel.open(file1)) {
                     try (FileLock lock2 = channel2.lock()) {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/88a30f56/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
index fd9791e..c1d8f0c 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
@@ -856,7 +856,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
             }
 
             for (Object f : res) {
-                System.out.append('\t').println(f);
+                outputDebugMessage("LsEntry: %s", f);
 
                 ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) f;
                 String name = entry.getFilename();
@@ -949,7 +949,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
                     for (Map.Entry<String, ?> de : data.entrySet()) {
                         String extName = de.getKey();
                         Object extValue = de.getValue();
-                        System.out.append('\t').append(extName).append(": ").println(extValue);
+                        outputDebugMessage("%s: %s", extName, extValue);
                         if (SftpConstants.EXT_SUPPORTED.equalsIgnoreCase(extName)) {
                             assertSupportedExtensions(extName, ((Supported) extValue).extensionNames);
                         } else if (SftpConstants.EXT_SUPPORTED2.equalsIgnoreCase(extName)) {
@@ -1204,7 +1204,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
             }
             assertFalse("Target link exists before linking: " + linkPath, Files.exists(linkPath, options));
 
-            System.out.append('\t').append("Symlink ").append(remLinkPath).append(" => ").println(remSrcPath);
+            outputDebugMessage("Symlink %s => %s", remLinkPath, remSrcPath);
             c.symlink(remSrcPath, remLinkPath);
 
             assertTrue("Symlink not created: " + linkPath, Files.exists(linkPath, options));

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/88a30f56/sshd-core/src/test/java/org/apache/sshd/util/test/BaseTestSupport.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/test/BaseTestSupport.java b/sshd-core/src/test/java/org/apache/sshd/util/test/BaseTestSupport.java
index 7409ebb..2e7d32b 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/test/BaseTestSupport.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/test/BaseTestSupport.java
@@ -67,6 +67,7 @@ public abstract class BaseTestSupport extends Assert {
     public static final String TEMP_SUBFOLDER_NAME = "temp";
     // can be used to override the 'localhost' with an address other than 127.0.0.1 in case it is required
     public static final String TEST_LOCALHOST = System.getProperty("org.apache.sshd.test.localhost", SshdSocketAddress.LOCALHOST_IP);
+    public static final boolean OUTPUT_DEBUG_MESSAGES = Boolean.parseBoolean(System.getProperty("org.apache.sshd.test.outputDebugMessages", "false"));
 
     // useful test sizes for keys
     @SuppressWarnings("boxing")
@@ -519,4 +520,16 @@ public abstract class BaseTestSupport extends Assert {
 
         return false;
     }
+
+    public static void outputDebugMessage(String format, Object ... args) {
+        if (OUTPUT_DEBUG_MESSAGES) {
+            outputDebugMessage(String.format(format, args));
+        }
+    }
+
+    public static void outputDebugMessage(Object message) {
+        if (OUTPUT_DEBUG_MESSAGES) {
+            System.out.append("===[DEBUG]=== ").println(message);
+        }
+    }
 }