cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [25/30] git commit: updated refs/heads/master to 64ff67d
Date Fri, 14 Aug 2015 19:47:48 GMT
CLOUDSTACK-8656: restructure of tests

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

Branch: refs/heads/master
Commit: bb8facc37c5ff5268a962feab7fd868a8437d4be
Parents: 882de20
Author: Daan Hoogland <daan@onecht.net>
Authored: Fri Aug 14 16:07:12 2015 +0200
Committer: Daan Hoogland <daan@onecht.net>
Committed: Fri Aug 14 16:07:12 2015 +0200

----------------------------------------------------------------------
 .../com/cloud/utils/db/TransactionTest.java     | 75 ++++----------------
 1 file changed, 14 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bb8facc3/framework/db/test/com/cloud/utils/db/TransactionTest.java
----------------------------------------------------------------------
diff --git a/framework/db/test/com/cloud/utils/db/TransactionTest.java b/framework/db/test/com/cloud/utils/db/TransactionTest.java
index 76bd5a5..fed6632 100644
--- a/framework/db/test/com/cloud/utils/db/TransactionTest.java
+++ b/framework/db/test/com/cloud/utils/db/TransactionTest.java
@@ -38,32 +38,17 @@ public class TransactionTest {
 
     @BeforeClass
     public static void oneTimeSetup() {
-        Connection conn = null;
-        PreparedStatement pstmt = null;
-        try {
-            conn = TransactionLegacy.getStandaloneConnection();
-
-            pstmt =
-                conn.prepareStatement("CREATE TABLE `cloud`.`test` (" + "`id` bigint unsigned
NOT NULL UNIQUE AUTO_INCREMENT," + "`fld_int` int unsigned,"
-                    + "`fld_long` bigint unsigned," + "`fld_string` varchar(255)," + "PRIMARY
KEY (`id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+        try (
+                Connection conn = TransactionLegacy.getStandaloneConnection();
+                PreparedStatement pstmt =
+                    conn.prepareStatement("CREATE TABLE `cloud`.`test` (" + "`id` bigint
unsigned NOT NULL UNIQUE AUTO_INCREMENT," + "`fld_int` int unsigned,"
+                        + "`fld_long` bigint unsigned," + "`fld_string` varchar(255)," +
"PRIMARY KEY (`id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+            ) {
 
             pstmt.execute();
 
         } catch (SQLException e) {
             throw new CloudRuntimeException("Problem with sql", e);
-        } finally {
-            if (pstmt != null) {
-                try {
-                    pstmt.close();
-                } catch (SQLException e) {
-                }
-            }
-            if (conn != null) {
-                try {
-                    conn.close();
-                } catch (SQLException e) {
-                }
-            }
         }
     }
 
@@ -157,57 +142,25 @@ public class TransactionTest {
      * Delete all records after each test, but table is still kept
      */
     public void tearDown() {
-        Connection conn = null;
-        PreparedStatement pstmt = null;
-        try {
-            conn = TransactionLegacy.getStandaloneConnection();
-
-            pstmt = conn.prepareStatement("truncate table `cloud`.`test`");
+        try (
+                Connection conn = TransactionLegacy.getStandaloneConnection();
+                PreparedStatement pstmt = conn.prepareStatement("truncate table `cloud`.`test`");
+            ) {
             pstmt.execute();
-
         } catch (SQLException e) {
             throw new CloudRuntimeException("Problem with sql", e);
-        } finally {
-            if (pstmt != null) {
-                try {
-                    pstmt.close();
-                } catch (SQLException e) {
-                }
-            }
-            if (conn != null) {
-                try {
-                    conn.close();
-                } catch (SQLException e) {
-                }
-            }
         }
     }
 
     @AfterClass
     public static void oneTimeTearDown() {
-        Connection conn = null;
-        PreparedStatement pstmt = null;
-        try {
-            conn = TransactionLegacy.getStandaloneConnection();
-
-            pstmt = conn.prepareStatement("DROP TABLE IF EXISTS `cloud`.`test`");
+        try (
+                Connection conn = TransactionLegacy.getStandaloneConnection();
+                PreparedStatement pstmt = conn.prepareStatement("DROP TABLE IF EXISTS `cloud`.`test`");
+            ) {
             pstmt.execute();
-
         } catch (SQLException e) {
             throw new CloudRuntimeException("Problem with sql", e);
-        } finally {
-            if (pstmt != null) {
-                try {
-                    pstmt.close();
-                } catch (SQLException e) {
-                }
-            }
-            if (conn != null) {
-                try {
-                    conn.close();
-                } catch (SQLException e) {
-                }
-            }
         }
     }
 }


Mime
View raw message