ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpapirkovs...@apache.org
Subject [4/4] ambari git commit: AMBARI-19799. Optimize DB initialization for Ambari Server Unit Tests. (mpapirkovskyy)
Date Wed, 01 Feb 2017 15:05:44 GMT
AMBARI-19799. Optimize DB initialization for Ambari Server Unit Tests. (mpapirkovskyy)


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

Branch: refs/heads/trunk
Commit: 3a7906c84737511475e718a0da50397b31ef7b52
Parents: 727a318
Author: Myroslav Papirkovskyi <mpapyrkovskyy@hortonworks.com>
Authored: Tue Jan 31 17:54:23 2017 +0200
Committer: Myroslav Papirkovskyi <mpapyrkovskyy@hortonworks.com>
Committed: Wed Feb 1 16:44:47 2017 +0200

----------------------------------------------------------------------
 .gitignore                                      |   1 +
 ambari-project/pom.xml                          |   2 +-
 ambari-server/pom.xml                           |  12 +-
 .../ambari/server/agent/HeartBeatHandler.java   |   4 +
 .../server/configuration/Configuration.java     |  40 +++-
 .../server/controller/ControllerModule.java     |   5 +-
 .../apache/ambari/server/orm/DBAccessor.java    |   1 +
 .../ambari/server/orm/DBAccessorImpl.java       |   5 +
 .../server/orm/entities/UpgradeEntity.java      |   2 +-
 .../server/orm/helpers/dbms/H2Helper.java       |  74 +++++++
 .../src/main/resources/META-INF/persistence.xml |  12 +-
 .../apache/ambari/annotations/LockAreaTest.java |   7 +-
 .../TransactionalLockInterceptorTest.java       |   7 +-
 .../apache/ambari/server/H2DatabaseCleaner.java | 124 +++++++++++
 .../ambari/server/StateRecoveryManagerTest.java |   6 +-
 .../ExecutionCommandWrapperTest.java            |   8 +
 .../ambari/server/actionmanager/StageTest.java  |  11 +-
 .../actionmanager/TestActionDBAccessorImpl.java |   8 +-
 .../server/actionmanager/TestActionManager.java |   9 +-
 .../actionmanager/TestActionScheduler.java      |   7 +-
 .../TestActionSchedulerThreading.java           |   8 +-
 .../ambari/server/actionmanager/TestStage.java  |   9 +
 .../server/agent/HeartbeatProcessorTest.java    |  10 +-
 .../server/agent/TestHeartbeatHandler.java      |   5 +-
 .../server/agent/TestHeartbeatMonitor.java      |   7 +-
 .../server/api/query/JpaSortBuilderTest.java    |   7 +
 .../server/api/services/AmbariMetaInfoTest.java |  12 +-
 .../api/services/PersistKeyValueImplTest.java   |   4 +-
 .../server/api/services/PersistServiceTest.java |   4 +-
 .../configuration/RecoveryConfigHelperTest.java |   4 +-
 .../AmbariCustomCommandExecutionHelperTest.java |   7 +-
 .../AmbariManagementControllerTest.java         |   7 +-
 .../server/controller/AmbariServerTest.java     |   5 +-
 .../BackgroundCustomCommandExecutionTest.java   |   7 +-
 ...hYarnCapacitySchedulerReleaseConfigTest.java |   7 +-
 .../RootServiceResponseFactoryTest.java         |   9 +
 .../internal/ActionResourceProviderTest.java    |   7 +-
 .../internal/AlertResourceProviderTest.java     |   4 +-
 .../internal/CalculatedStatusTest.java          |   8 +
 ...ClusterStackVersionResourceProviderTest.java | 214 ++++++++++---------
 ...leRepositoryVersionResourceProviderTest.java |   8 +-
 .../internal/ComponentResourceProviderTest.java |   2 +
 .../HostStackVersionResourceProviderTest.java   |   8 +-
 .../internal/JMXHostProviderTest.java           |   8 +-
 .../RepositoryVersionResourceProviderTest.java  |   8 +-
 .../StackArtifactResourceProviderTest.java      |   8 +-
 .../StackDefinedPropertyProviderTest.java       |   4 +-
 .../UpgradeResourceProviderHDP22Test.java       |   8 +-
 .../internal/UpgradeResourceProviderTest.java   |   9 +-
 .../UpgradeSummaryResourceProviderTest.java     |  10 +-
 .../internal/UserResourceProviderDBTest.java    |   7 +-
 .../VersionDefinitionResourceProviderTest.java  |   4 +-
 .../LogSearchDataRetrievalServiceTest.java      |   1 -
 .../RestMetricsPropertyProviderTest.java        |   9 +
 .../utilities/DatabaseCheckerTest.java          |   6 +-
 .../GeneralServiceCalculatedStateTest.java      |  10 +-
 .../apache/ambari/server/events/EventsTest.java |   6 +-
 .../HostVersionOutOfSyncListenerTest.java       |   7 +-
 .../metadata/AgentAlertDefinitionsTest.java     |  11 +
 .../server/metadata/RoleCommandOrderTest.java   |   7 +-
 .../ambari/server/metadata/RoleGraphTest.java   |   7 +-
 .../ambari/server/orm/DBAccessorImplTest.java   |  20 +-
 .../ambari/server/orm/JdbcPropertyTest.java     |   4 +-
 .../apache/ambari/server/orm/OrmTestHelper.java |  12 +-
 .../apache/ambari/server/orm/TestOrmImpl.java   |   8 +-
 .../server/orm/dao/AlertDefinitionDAOTest.java  |   6 +-
 .../server/orm/dao/AlertDispatchDAOTest.java    |   6 +-
 .../ambari/server/orm/dao/AlertsDAOTest.java    |   8 +-
 .../server/orm/dao/ClusterVersionDAOTest.java   |  12 +-
 .../server/orm/dao/ConfigGroupDAOTest.java      |  19 +-
 .../ambari/server/orm/dao/CrudDAOTest.java      |  11 +-
 .../orm/dao/HostConfigMappingDAOTest.java       |   7 +-
 .../server/orm/dao/HostRoleCommandDAOTest.java  |   9 +-
 .../server/orm/dao/HostVersionDAOTest.java      |  11 +-
 .../orm/dao/RepositoryVersionDAOTest.java       |   7 +-
 .../ambari/server/orm/dao/RequestDAOTest.java   |   7 +-
 .../server/orm/dao/RequestScheduleDAOTest.java  |   7 +-
 .../server/orm/dao/ServiceConfigDAOTest.java    |  64 ++++--
 .../ambari/server/orm/dao/SettingDAOTest.java   |   7 +
 .../ambari/server/orm/dao/StageDAOTest.java     |  10 +-
 .../orm/dao/TopologyLogicalRequestDAOTest.java  |   7 +-
 .../server/orm/dao/TopologyRequestDAOTest.java  |   7 +-
 .../ambari/server/orm/dao/UpgradeDAOTest.java   |   9 +-
 .../ambari/server/orm/dao/WidgetDAOTest.java    |   8 +-
 .../server/orm/dao/WidgetLayoutDAOTest.java     |   8 +-
 .../scheduler/ExecutionScheduleManagerTest.java |   4 +-
 .../server/security/AmbariLdapUtilsTest.java    |   1 -
 .../AmbariBasicAuthenticationFilterTest.java    |   6 +-
 ...uthenticationProviderForDNWithSpaceTest.java |   4 +-
 .../AmbariLdapAuthenticationProviderTest.java   |   4 +-
 .../AmbariLocalUserProviderTest.java            |   7 +
 .../AmbariPamAuthenticationProviderTest.java    |   4 +-
 .../security/authorization/TestUsers.java       |   7 +-
 .../security/ldap/LdapPerformanceTest.java      |   8 +
 .../serveraction/ServerActionExecutorTest.java  |  11 +-
 .../kerberos/KerberosServerActionTest.java      |   2 +-
 .../AutoSkipFailedSummaryActionTest.java        |   6 +-
 .../ComponentVersionCheckActionTest.java        |   6 +-
 .../upgrades/ConfigureActionTest.java           |   6 +-
 .../upgrades/UpgradeActionTest.java             |   6 +-
 .../server/stageplanner/TestStagePlanner.java   |   7 +-
 .../ambari/server/state/ConfigGroupTest.java    |  17 +-
 .../ambari/server/state/ConfigHelperTest.java   |   7 +-
 .../server/state/ConfigMergeHelperTest.java     |   8 +-
 .../server/state/RequestExecutionTest.java      |   4 +-
 .../server/state/ServiceComponentTest.java      |   7 +-
 .../apache/ambari/server/state/ServiceTest.java |   7 +-
 .../ambari/server/state/UpgradeHelperTest.java  |   9 +-
 .../alerts/AggregateAlertListenerTest.java      |   6 +-
 .../state/alerts/AlertEventPublisherTest.java   |  22 +-
 .../state/alerts/AlertReceivedListenerTest.java |  10 +-
 .../alerts/AlertStateChangedEventTest.java      |   4 +-
 .../state/alerts/InitialAlertEventTest.java     |   6 +-
 .../state/cluster/AlertDataManagerTest.java     |  10 +-
 .../state/cluster/ClusterDeadlockTest.java      |   7 +-
 .../server/state/cluster/ClusterImplTest.java   |  11 +-
 .../server/state/cluster/ClusterTest.java       |  15 +-
 .../state/cluster/ClustersDeadlockTest.java     |   7 +-
 .../server/state/cluster/ClustersTest.java      |   7 +-
 .../ConcurrentServiceConfigVersionTest.java     |   7 +-
 ...omponentHostConcurrentWriteDeadlockTest.java |   7 +-
 .../ambari/server/state/host/HostTest.java      |   9 +-
 .../services/RetryUpgradeActionServiceTest.java |   8 +
 .../state/stack/ConfigUpgradePackTest.java      |   8 +-
 .../state/stack/ConfigUpgradeValidityTest.java  |   8 +-
 .../ambari/server/state/stack/OSFamilyTest.java |  12 +-
 .../server/state/stack/UpgradePackTest.java     |   8 +-
 .../svccomphost/ServiceComponentHostTest.java   |   7 +-
 .../server/upgrade/StackUpgradeUtilTest.java    |   4 +-
 .../server/upgrade/UpgradeCatalog200Test.java   |   6 +-
 .../server/upgrade/UpgradeCatalog210Test.java   |   6 +-
 .../server/upgrade/UpgradeCatalog2121Test.java  |   8 +-
 .../server/upgrade/UpgradeCatalog212Test.java   |   7 +-
 .../server/upgrade/UpgradeCatalog220Test.java   |   6 +-
 .../server/upgrade/UpgradeCatalog240Test.java   |   8 +-
 .../server/upgrade/UpgradeCatalog242Test.java   |   6 +-
 .../server/upgrade/UpgradeCatalogTest.java      |   6 +-
 pom.xml                                         |   2 +
 138 files changed, 1029 insertions(+), 469 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 43edfd9..a40e61a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,3 +25,4 @@ ambari-metrics/ambari-metrics-host-monitoring/src/main/python/psutil/build/
 rebel.xml
 rebel-remote.xml
 out
+createDDL.jdbc

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-project/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-project/pom.xml b/ambari-project/pom.xml
index 0eab275..6e8ef0e 100644
--- a/ambari-project/pom.xml
+++ b/ambari-project/pom.xml
@@ -553,7 +553,7 @@
           <redirectTestOutputToFile>true</redirectTestOutputToFile>
           <forkedProcessTimeoutInSeconds>900</forkedProcessTimeoutInSeconds>
           <reuseForks>false</reuseForks>
-          <forkCount>1C</forkCount>
+          <forkCount>1</forkCount>
         </configuration>
       </plugin>
       <plugin>

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index 90c6b61..a9518e1 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -272,7 +272,6 @@
         <configuration>
           <excludes>
             <exclude>pass.txt</exclude>
-            <exclude>derby.log</exclude>
             <exclude>src/test/resources/version</exclude>
             <exclude>src/test/resources/users.ldif</exclude>
             <exclude>src/test/resources/gsInstaller-hosts.txt</exclude>
@@ -1066,14 +1065,9 @@
       <version>3.0</version>
     </dependency>
     <dependency>
-      <groupId>org.apache.derby</groupId>
-      <artifactId>derby</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.derby</groupId>
-      <artifactId>derbytools</artifactId>
-      <version>10.11.1.1</version>
-      <scope>test</scope>
+      <groupId>com.h2database</groupId>
+      <artifactId>h2</artifactId>
+      <version>1.4.193</version>
     </dependency>
     <dependency>
       <groupId>org.springframework.security</groupId>

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
index b7d7476..7c833f6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
@@ -664,4 +664,8 @@ public class HeartBeatHandler {
     }
   }
 
+  public void stop() {
+    heartbeatMonitor.shutdown();
+    heartbeatProcessor.stopAsync();
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 0c51576..5020790 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -237,17 +237,36 @@ public class Configuration {
   public static final String DEFAULT_DERBY_SCHEMA = "ambari";
 
   /**
-   * The JDBC URL to use when creating a {@link DatabaseType#DERBY} database for
+   * The schema to use when creating a {@link DatabaseType#H2} database for
+   * unit tests.
+   */
+  public static final String DEFAULT_H2_SCHEMA = "ambari";
+
+  /**
+   * The JDBC URL to use when creating a {@link DatabaseType#H2} database for
    * unit tests.
    */
   public static final String JDBC_IN_MEMORY_URL = String.format(
-      "jdbc:derby:memory:myDB/%s;create=true", DEFAULT_DERBY_SCHEMA);
+      "jdbc:h2:mem:%1$s;ALIAS_COLUMN_NAME=TRUE;INIT=CREATE SCHEMA IF NOT EXISTS %1$s\\;SET SCHEMA %1$s;",
+      DEFAULT_DERBY_SCHEMA);
+
+  /**
+   * The H2 driver to use when creating a {@link DatabaseType#H2} database
+   * for unit tests.
+   */
+  public static final String JDBC_IN_MEMORY_DRIVER = "org.h2.Driver";
 
   /**
-   * The Derby driver to use when creating a {@link DatabaseType#DERBY} database
+   * The H2 default user driver to use when creating a {@link DatabaseType#H2} database
    * for unit tests.
    */
-  public static final String JDBC_IN_MEMORY_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
+  public static final String JDBC_IN_MEMORY_USER = "sa";
+
+  /**
+   * The H2 default password to use when creating a {@link DatabaseType#H2} database
+   * for unit tests.
+   */
+  public static final String JDBC_IN_MEMORY_PASSWORD = "";
 
   /**
    * The JSSE property which governs the location of the keystore file
@@ -2673,7 +2692,8 @@ public class Configuration {
     MYSQL("mysql"),
     DERBY("derby"),
     SQL_SERVER("sqlserver"),
-    SQL_ANYWHERE("sqlanywhere");
+    SQL_ANYWHERE("sqlanywhere"),
+    H2("h2");
 
     private static final Map<String, DatabaseType> m_mappedTypes =
       new HashMap<String, Configuration.DatabaseType>(5);
@@ -3824,10 +3844,16 @@ public class Configuration {
   }
 
   public String getDatabaseUser() {
+    if (getPersistenceType() == PersistenceType.IN_MEMORY) {
+      return JDBC_IN_MEMORY_USER;
+    }
     return getProperty(SERVER_JDBC_USER_NAME);
   }
 
   public String getDatabasePassword() {
+    if (getPersistenceType() == PersistenceType.IN_MEMORY) {
+      return JDBC_IN_MEMORY_PASSWORD;
+    }
     String passwdProp = properties.getProperty(SERVER_JDBC_USER_PASSWD.getKey());
     String dbpasswd = null;
     boolean isPasswordAlias = false;
@@ -4819,6 +4845,8 @@ public class Configuration {
       databaseType = DatabaseType.SQL_SERVER;
     } else if (dbUrl.contains(DatabaseType.SQL_ANYWHERE.getName())) {
       databaseType = DatabaseType.SQL_ANYWHERE;
+    } else if (dbUrl.contains(DatabaseType.H2.getName())) {
+      databaseType = DatabaseType.H2;
     } else {
       throw new RuntimeException(
         "The database type could be not determined from the JDBC URL "
@@ -4845,6 +4873,8 @@ public class Configuration {
       databaseSchema = getDatabaseUser();
     } else if (databaseType.equals(DatabaseType.DERBY)) {
       databaseSchema = DEFAULT_DERBY_SCHEMA;
+    } else if (databaseType.equals(DatabaseType.H2)) {
+      databaseSchema = DEFAULT_H2_SCHEMA;
     } else {
       databaseSchema = null;
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
index b7c9e85..b634a62 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
@@ -226,7 +226,10 @@ public class ControllerModule extends AbstractModule {
       case IN_MEMORY:
         properties.setProperty(JDBC_URL, Configuration.JDBC_IN_MEMORY_URL);
         properties.setProperty(JDBC_DRIVER, Configuration.JDBC_IN_MEMORY_DRIVER);
-        properties.setProperty(DDL_GENERATION, DROP_AND_CREATE);
+        properties.setProperty(JDBC_USER, Configuration.JDBC_IN_MEMORY_USER);
+        properties.setProperty(JDBC_PASSWORD, Configuration.JDBC_IN_MEMORY_PASSWORD);
+        properties.setProperty(DDL_GENERATION, CREATE_ONLY);
+        properties.setProperty(DDL_GENERATION_MODE, DDL_BOTH_GENERATION);
         properties.setProperty(THROW_EXCEPTIONS, "true");
         break;
       case REMOTE:

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
index b8a760f..5d9eb6c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
@@ -623,6 +623,7 @@ public interface DBAccessor {
     MYSQL,
     POSTGRES,
     DERBY,
+    H2,
     UNKNOWN
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
index c645d6d..1c0ab30 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
@@ -43,6 +43,7 @@ import org.apache.ambari.server.orm.helpers.ScriptRunner;
 import org.apache.ambari.server.orm.helpers.dbms.DbmsHelper;
 import org.apache.ambari.server.orm.helpers.dbms.DerbyHelper;
 import org.apache.ambari.server.orm.helpers.dbms.GenericDbmsHelper;
+import org.apache.ambari.server.orm.helpers.dbms.H2Helper;
 import org.apache.ambari.server.orm.helpers.dbms.MySqlHelper;
 import org.apache.ambari.server.orm.helpers.dbms.OracleHelper;
 import org.apache.ambari.server.orm.helpers.dbms.PostgresHelper;
@@ -55,6 +56,7 @@ import org.eclipse.persistence.logging.AbstractSessionLog;
 import org.eclipse.persistence.logging.SessionLogEntry;
 import org.eclipse.persistence.platform.database.DatabasePlatform;
 import org.eclipse.persistence.platform.database.DerbyPlatform;
+import org.eclipse.persistence.platform.database.H2Platform;
 import org.eclipse.persistence.platform.database.MySQLPlatform;
 import org.eclipse.persistence.platform.database.OraclePlatform;
 import org.eclipse.persistence.platform.database.PostgreSQLPlatform;
@@ -130,6 +132,9 @@ public class DBAccessorImpl implements DBAccessor {
     } else if (databasePlatform instanceof DerbyPlatform) {
       dbType = DbType.DERBY;
       return new DerbyHelper(databasePlatform);
+    } else if (databasePlatform instanceof H2Platform) {
+      dbType = DbType.H2;
+      return new H2Helper(databasePlatform);
     } else {
       dbType = DbType.UNKNOWN;
       return new GenericDbmsHelper(databasePlatform);

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/UpgradeEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/UpgradeEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/UpgradeEntity.java
index 2c5cbfb..7421ca1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/UpgradeEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/UpgradeEntity.java
@@ -54,7 +54,7 @@ import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
   @NamedQuery(name = "UpgradeEntity.findUpgrade",
       query = "SELECT u FROM UpgradeEntity u WHERE u.upgradeId = :upgradeId"),
   @NamedQuery(name = "UpgradeEntity.findLatestForClusterInDirection",
-      query = "SELECT u FROM UpgradeEntity u JOIN RequestEntity r ON u.requestId = r.requestId WHERE u.clusterId = :clusterId AND u.direction = :direction ORDER BY r.startTime DESC"),
+      query = "SELECT u FROM UpgradeEntity u JOIN RequestEntity r ON u.requestId = r.requestId WHERE u.clusterId = :clusterId AND u.direction = :direction ORDER BY r.startTime DESC, u.upgradeId DESC"),
   @NamedQuery(name = "UpgradeEntity.findLatestForCluster",
       query = "SELECT u FROM UpgradeEntity u JOIN RequestEntity r ON u.requestId = r.requestId WHERE u.clusterId = :clusterId ORDER BY r.startTime DESC"),
 })

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/H2Helper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/H2Helper.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/H2Helper.java
new file mode 100644
index 0000000..e6cb8ab
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/H2Helper.java
@@ -0,0 +1,74 @@
+/**
+ * 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.ambari.server.orm.helpers.dbms;
+
+import org.apache.ambari.server.orm.DBAccessor;
+import org.eclipse.persistence.platform.database.DatabasePlatform;
+
+public class H2Helper extends GenericDbmsHelper {
+  public H2Helper(DatabasePlatform databasePlatform) {
+    super(databasePlatform);
+  }
+
+  @Override
+  public boolean supportsColumnTypeChange() {
+    return false; //type change is dramatically limited to varchar length increase only, almost useless
+  }
+
+  //+
+  @Override
+  public String getRenameColumnStatement(String tableName, String oldName, DBAccessor.DBColumnInfo columnInfo) {
+    StringBuilder builder = new StringBuilder();
+
+    builder.append("ALTER TABLE ").append(tableName).append(" ALTER COLUMN ").append(oldName);
+    builder.append(" RENAME TO ").append(columnInfo.getName());
+
+    return builder.toString();
+  }
+
+  @Override
+  public StringBuilder writeColumnModifyString(StringBuilder builder, DBAccessor.DBColumnInfo columnInfo) {
+    builder.append(" ALTER COLUMN ").append(columnInfo.getName())
+      .append(" SET DATA TYPE ");
+    writeColumnType(builder, columnInfo);
+
+    return builder;
+  }
+
+  //+
+  @Override
+  public StringBuilder writeSetNullableString(StringBuilder builder,
+      String tableName, DBAccessor.DBColumnInfo columnInfo, boolean nullable) {
+    builder.append(" ALTER COLUMN ").append(columnInfo.getName()).append(" SET");
+    String nullStatement = nullable ? " NULL" : " NOT NULL";
+    builder.append(nullStatement);
+    return builder;
+  }
+
+  @Override
+  public String writeGetTableConstraints(String databaseName, String tableName){
+    StringBuilder statement = new StringBuilder()
+      .append("SELECT")
+        .append(" C.CONSTRAINTNAME AS CONSTRAINT_NAME,")
+        .append(" C.TYPE AS CONSTRAINT_TYPE")
+      .append(" FROM SYS.SYSCONSTRAINTS AS C, SYS.SYSTABLES AS T")
+      .append(" WHERE C.TABLEID = T.TABLEID AND T.TABLENAME = '").append(tableName).append("'");
+    return statement.toString();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/main/resources/META-INF/persistence.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/META-INF/persistence.xml b/ambari-server/src/main/resources/META-INF/persistence.xml
index 0375650..3aa7689 100644
--- a/ambari-server/src/main/resources/META-INF/persistence.xml
+++ b/ambari-server/src/main/resources/META-INF/persistence.xml
@@ -106,8 +106,8 @@
       <property name="eclipselink.connection-pool.sequence" value="true" />
       <property name="eclipselink.weaving" value="static" />
       <property name="eclipselink.session.customizer" value="org.apache.ambari.server.orm.EclipseLinkSessionCustomizer"/>
-      <property name="eclipselink.logging.logger" value="org.apache.ambari.server.logging.EclipseLinkLogger"/>
-      <property name="eclipselink.logging.level" value="INFO"/>
+      <!--<property name="eclipselink.logging.logger" value="org.apache.ambari.server.logging.EclipseLinkLogger"/>-->
+      <!--<property name="eclipselink.logging.level" value="INFO"/>-->
     </properties>
   </persistence-unit>
 
@@ -119,8 +119,8 @@
       <property name="eclipselink.cache.size.default" value="10000" />
       <property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
       <property name="eclipselink.weaving" value="static" />
-      <property name="eclipselink.logging.logger" value="org.apache.ambari.server.logging.EclipseLinkLogger"/>
-      <property name="eclipselink.logging.level" value="INFO"/>
+      <!--<property name="eclipselink.logging.logger" value="org.apache.ambari.server.logging.EclipseLinkLogger"/>-->
+      <!--<property name="eclipselink.logging.level" value="INFO"/>-->
     </properties>
   </persistence-unit>
   <persistence-unit name="ambari-view-migration" transaction-type="RESOURCE_LOCAL">
@@ -130,8 +130,8 @@
       <property name="eclipselink.cache.size.default" value="10000" />
       <property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
       <property name="eclipselink.weaving" value="static" />
-      <property name="eclipselink.logging.logger" value="org.apache.ambari.server.logging.EclipseLinkLogger"/>
-      <property name="eclipselink.logging.level" value="INFO"/>
+      <!--<property name="eclipselink.logging.logger" value="org.apache.ambari.server.logging.EclipseLinkLogger"/>-->
+      <!--<property name="eclipselink.logging.level" value="INFO"/>-->
     </properties>
   </persistence-unit>
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/annotations/LockAreaTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/annotations/LockAreaTest.java b/ambari-server/src/test/java/org/apache/ambari/annotations/LockAreaTest.java
index 2208ce4..fc5e81a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/annotations/LockAreaTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/annotations/LockAreaTest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.ambari.annotations;
 
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
@@ -26,6 +27,7 @@ import java.util.concurrent.locks.ReadWriteLock;
 
 import org.apache.ambari.annotations.TransactionalLock.LockArea;
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.TransactionalLocks;
@@ -35,7 +37,6 @@ import org.junit.Test;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
 
 import junit.framework.Assert;
 
@@ -53,8 +54,8 @@ public class LockAreaTest {
   }
 
   @After
-  public void teardown() throws AmbariException {
-    m_injector.getInstance(PersistService.class).stop();
+  public void teardown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(m_injector);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/annotations/TransactionalLockInterceptorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/annotations/TransactionalLockInterceptorTest.java b/ambari-server/src/test/java/org/apache/ambari/annotations/TransactionalLockInterceptorTest.java
index 7d7f47b..dcd1546 100644
--- a/ambari-server/src/test/java/org/apache/ambari/annotations/TransactionalLockInterceptorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/annotations/TransactionalLockInterceptorTest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.ambari.annotations;
 
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
@@ -24,6 +25,7 @@ import java.util.concurrent.locks.ReadWriteLock;
 import org.apache.ambari.annotations.TransactionalLock.LockArea;
 import org.apache.ambari.annotations.TransactionalLock.LockType;
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.TransactionalLocks;
@@ -38,7 +40,6 @@ import com.google.inject.Binder;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 import com.google.inject.Module;
-import com.google.inject.persist.PersistService;
 import com.google.inject.persist.Transactional;
 import com.google.inject.util.Modules;
 
@@ -58,8 +59,8 @@ public class TransactionalLockInterceptorTest {
   }
 
   @After
-  public void teardown() throws AmbariException {
-    m_injector.getInstance(PersistService.class).stop();
+  public void teardown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(m_injector);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/H2DatabaseCleaner.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/H2DatabaseCleaner.java b/ambari-server/src/test/java/org/apache/ambari/server/H2DatabaseCleaner.java
new file mode 100644
index 0000000..91477eb
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/H2DatabaseCleaner.java
@@ -0,0 +1,124 @@
+/**
+ * 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.ambari.server;
+
+import static org.eclipse.persistence.config.PersistenceUnitProperties.DEFAULT_CREATE_JDBC_FILE_NAME;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import javax.persistence.metamodel.EntityType;
+
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.orm.DBAccessorImpl;
+import org.apache.commons.collections.CollectionUtils;
+
+import com.google.inject.Injector;
+import com.google.inject.persist.PersistService;
+
+public class H2DatabaseCleaner {
+  private static final String SEQ_INSERT_PREFIX = "INSERT INTO ambari_sequences";
+  private static List<String> seqInsertStatements;
+
+  public static void clearDatabaseAndStopPersistenceService(Injector injector) throws AmbariException, SQLException {
+    clearDatabase(injector.getProvider(EntityManager.class).get());
+    injector.getInstance(PersistService.class).stop();
+  }
+
+  public static void clearDatabase(EntityManager entityManager) throws AmbariException, SQLException {
+    clearDatabase(entityManager, Configuration.JDBC_IN_MEMORY_URL,
+      Configuration.JDBC_IN_MEMORY_USER, Configuration.JDBC_IN_MEMORY_PASSWORD);
+  }
+
+  private static List<String> collectSequenceInserts() {
+    try {
+      ArrayList<String> statementList = new ArrayList<>();
+      for (String s : Files.readAllLines(Paths.get(DEFAULT_CREATE_JDBC_FILE_NAME), Charset.defaultCharset())) {
+        if (s.startsWith(SEQ_INSERT_PREFIX)) {
+          statementList.add(s);
+        }
+      }
+      return statementList;
+    } catch (IOException e) {
+      return Collections.emptyList();
+    }
+  }
+
+  //TODO all tests this method is used in should be modified to remove hardcoded IDs
+  public static void resetSequences(Injector injector) {
+    DBAccessorImpl dbAccessor = injector.getInstance(DBAccessorImpl.class);
+    try {
+      if (dbAccessor.tableExists("ambari_sequences")) {
+        if (seqInsertStatements == null) {
+          seqInsertStatements = collectSequenceInserts();
+        }
+        if (!CollectionUtils.isEmpty(seqInsertStatements)) {
+          dbAccessor.truncateTable("ambari_sequences");
+
+          for (String insert : seqInsertStatements) {
+            dbAccessor.executeUpdate(insert);
+          }
+        }
+
+      }
+    } catch (SQLException ignored) {
+    }
+  }
+
+  public static void clearDatabase(EntityManager entityManager, String dbURL, String dbUser, String dbPass) throws SQLException {
+    Connection connection = DriverManager.getConnection(dbURL, dbUser, dbPass);
+    Statement s = connection.createStatement();
+
+    try {
+      // Disable FK
+      s.execute("SET REFERENTIAL_INTEGRITY FALSE");
+
+      entityManager.getTransaction().begin();
+      // Truncate tables for all entities
+      for (EntityType<?> entity : entityManager.getMetamodel().getEntities()) {
+        Query query = entityManager.createQuery("DELETE FROM " + entity.getName() + " em");
+        query.executeUpdate();
+//        final String tableName = entity.getBindableJavaType().getAnnotation(Table.class).name();
+//        s.executeUpdate("TRUNCATE TABLE " + tableName);
+      }
+
+      entityManager.getTransaction().commit();
+
+      // Enable FK
+      s.execute("SET REFERENTIAL_INTEGRITY TRUE");
+
+      //reset shared cache
+      entityManager.getEntityManagerFactory().getCache().evictAll();
+    } finally {
+      s.close();
+      connection.close();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/StateRecoveryManagerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/StateRecoveryManagerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/StateRecoveryManagerTest.java
index a413ce3..c5be8f4 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/StateRecoveryManagerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/StateRecoveryManagerTest.java
@@ -26,6 +26,7 @@ import static org.easymock.EasyMock.replay;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 
+import java.sql.SQLException;
 import java.util.ArrayList;
 
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
@@ -46,7 +47,6 @@ import org.junit.Test;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
 import com.google.inject.util.Modules;
 
 public class StateRecoveryManagerTest {
@@ -67,8 +67,8 @@ public class StateRecoveryManagerTest {
   }
 
   @After
-  public void teardown() {
-    injector.getInstance(PersistService.class).stop();
+  public void teardown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
index 62ce93b..893c3fb 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
@@ -19,6 +19,7 @@
 package org.apache.ambari.server.actionmanager;
 
 
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -28,6 +29,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.agent.AgentCommand.AgentCommandType;
@@ -42,6 +44,7 @@ import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartEvent;
 import org.apache.ambari.server.utils.StageUtils;
 import org.codehaus.jettison.json.JSONException;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -262,4 +265,9 @@ public class ExecutionCommandWrapperTest {
     Assert.assertEquals(SERVICE_SITE_VAL5, mergedConfig.get(SERVICE_SITE_NAME5));
     Assert.assertEquals(SERVICE_SITE_VAL6_H, mergedConfig.get(SERVICE_SITE_NAME6));
   }
+
+  @AfterClass
+  public static void tearDown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/StageTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/StageTest.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/StageTest.java
index 331f4fb..89627f7 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/StageTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/StageTest.java
@@ -20,9 +20,12 @@ package org.apache.ambari.server.actionmanager;
 
 import static org.junit.Assert.assertEquals;
 
+import java.sql.SQLException;
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
@@ -31,6 +34,7 @@ import org.apache.ambari.server.serveraction.ServerAction;
 import org.apache.ambari.server.serveraction.upgrades.ConfigureAction;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostServerActionEvent;
 import org.apache.ambari.server.utils.StageUtils;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -79,4 +83,9 @@ public class StageTest {
 
     assertEquals("user1", actionUserName);
   }
-}
\ No newline at end of file
+
+  @After
+  public void tearDown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
index 1ca777d..177ac70 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -30,6 +31,7 @@ import javax.persistence.EntityManager;
 import javax.persistence.NamedQuery;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.agent.CommandReport;
@@ -63,7 +65,6 @@ import com.google.inject.Guice;
 import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.Singleton;
-import com.google.inject.persist.PersistService;
 import com.google.inject.util.Modules;
 
 import junit.framework.Assert;
@@ -103,6 +104,7 @@ public class TestActionDBAccessorImpl {
     injector  = Guice.createInjector(Modules.override(defaultTestModule)
       .with(new TestActionDBAccessorModule()));
 
+    H2DatabaseCleaner.resetSequences(injector);
     injector.getInstance(GuiceJpaInitializer.class);
 
     // initialize AmbariMetaInfo so that the stacks are populated into the DB
@@ -124,8 +126,8 @@ public class TestActionDBAccessorImpl {
   }
 
   @After
-  public void tearDown() throws AmbariException {
-    injector.getInstance(PersistService.class).stop();
+  public void tearDown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
index da54789..d5f2475 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
@@ -27,11 +27,13 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
 
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.agent.ActionQueue;
@@ -53,7 +55,6 @@ import org.junit.Test;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
 import com.google.inject.persist.UnitOfWork;
 
 import junit.framework.Assert;
@@ -73,7 +74,9 @@ public class TestActionManager {
   @Before
   public void setup() throws AmbariException {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
+    H2DatabaseCleaner.resetSequences(injector);
     injector.getInstance(GuiceJpaInitializer.class);
+
     clusters = injector.getInstance(Clusters.class);
     stageFactory = injector.getInstance(StageFactory.class);
 
@@ -86,8 +89,8 @@ public class TestActionManager {
   }
 
   @After
-  public void teardown() throws AmbariException {
-    injector.getInstance(PersistService.class).stop();
+  public void tearDown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
index 6cc511e..ade625a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
@@ -41,6 +41,7 @@ import static org.mockito.Mockito.when;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -57,6 +58,7 @@ import java.util.concurrent.TimeUnit;
 import javax.persistence.EntityManager;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.ServiceComponentHostNotFoundException;
@@ -114,7 +116,6 @@ import com.google.inject.Guice;
 import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.Provider;
-import com.google.inject.persist.PersistService;
 import com.google.inject.persist.UnitOfWork;
 
 import junit.framework.Assert;
@@ -161,8 +162,8 @@ public class TestActionScheduler {
   }
 
   @After
-  public void teardown() {
-    injector.getInstance(PersistService.class).stop();
+  public void teardown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java
index 246c8b3..217f95e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java
@@ -20,6 +20,7 @@ package org.apache.ambari.server.actionmanager;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
@@ -27,6 +28,8 @@ import java.util.concurrent.Semaphore;
 
 import javax.persistence.EntityManager;
 
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.events.publishers.JPAEventPublisher;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
@@ -46,7 +49,6 @@ import com.google.common.collect.Sets;
 import com.google.inject.Guice;
 import com.google.inject.Inject;
 import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
 import com.google.inject.persist.UnitOfWork;
 
 import junit.framework.Assert;
@@ -78,8 +80,8 @@ public class TestActionSchedulerThreading {
    * Cleanup test methods.
    */
   @After
-  public void teardown() {
-    injector.getInstance(PersistService.class).stop();
+  public void tearDown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestStage.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestStage.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestStage.java
index 1047a73..c388d08 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestStage.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestStage.java
@@ -19,15 +19,19 @@ package org.apache.ambari.server.actionmanager;
 
 import static org.junit.Assert.assertEquals;
 
+import java.sql.SQLException;
 import java.util.Map;
 import java.util.TreeMap;
 
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.agent.ExecutionCommand;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.utils.StageUtils;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -75,4 +79,9 @@ public class TestStage {
     assertEquals("My Context", stage.getRequestContext());
     assertEquals(CLUSTER_HOST_INFO, stage.getClusterHostInfo());
   }
+
+  @After
+  public void tearDown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
index 4a5cb06..4a888f0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
@@ -36,6 +36,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -43,6 +44,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.ActionDBAccessor;
@@ -92,7 +94,6 @@ import com.google.gson.JsonObject;
 import com.google.inject.Guice;
 import com.google.inject.Inject;
 import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
 import com.google.inject.persist.UnitOfWork;
 
 import junit.framework.Assert;
@@ -143,14 +144,15 @@ public class HeartbeatProcessorTest {
 
   @Before
   public void setup() throws Exception {
+    H2DatabaseCleaner.resetSequences(injector);
     injector.getInstance(GuiceJpaInitializer.class);
     injector.injectMembers(this);
     EasyMock.replay(injector.getInstance(AuditLogger.class));
   }
 
   @After
-  public void teardown() throws AmbariException {
-    injector.getInstance(PersistService.class).stop();
+  public void teardown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
   }
 
   @Test
@@ -1364,4 +1366,4 @@ public class HeartbeatProcessorTest {
 
 
 
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
index e7588c7..ba03ae1 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
@@ -57,6 +57,7 @@ import java.util.Map;
 import javax.xml.bind.JAXBException;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.ActionDBAccessor;
@@ -107,7 +108,6 @@ import org.slf4j.LoggerFactory;
 import com.google.inject.Guice;
 import com.google.inject.Inject;
 import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
 
 import junit.framework.Assert;
 
@@ -161,7 +161,7 @@ public class TestHeartbeatHandler {
 
   @After
   public void teardown() throws Exception {
-    injector.getInstance(PersistService.class).stop();
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
     EasyMock.reset(auditLogger);
   }
 
@@ -444,6 +444,7 @@ public class TestHeartbeatHandler {
 
     HeartBeatResponse hbr = handler.handleHeartBeat(hb);
     assertNull(hbr.getRecoveryConfig());
+    handler.stop();
   }
 
   //

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
index 4d129a9..1b9c28b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.atLeast;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
+import java.sql.SQLException;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -33,6 +34,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
@@ -65,7 +67,6 @@ import org.slf4j.LoggerFactory;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
 
 public class TestHeartbeatMonitor {
 
@@ -92,8 +93,8 @@ public class TestHeartbeatMonitor {
   }
 
   @After
-  public void teardown() {
-    injector.getInstance(PersistService.class).stop();
+  public void teardown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
   }
 
   private void setOsFamily(Host host, String osFamily, String osVersion) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/api/query/JpaSortBuilderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/query/JpaSortBuilderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/query/JpaSortBuilderTest.java
index b9bfc50..adbcd32 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/query/JpaSortBuilderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/query/JpaSortBuilderTest.java
@@ -27,6 +27,7 @@ import javax.persistence.criteria.Order;
 import javax.persistence.criteria.Root;
 import javax.persistence.metamodel.SingularAttribute;
 
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.controller.internal.AlertHistoryResourceProvider;
 import org.apache.ambari.server.controller.internal.SortRequestImpl;
 import org.apache.ambari.server.controller.spi.Predicate;
@@ -38,6 +39,7 @@ import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.entities.AlertHistoryEntity;
 import org.apache.ambari.server.orm.entities.AlertHistoryEntity_;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -60,6 +62,11 @@ public class JpaSortBuilderTest {
     m_injector.injectMembers(this);
   }
 
+  @After
+  public void teardown() throws Exception {
+    H2DatabaseCleaner.clearDatabase(m_injector.getProvider(EntityManager.class).get());
+  }
+
   /**
    * Tests that adding a sort does not create another {@link Root} in the
    * {@link CriteriaQuery}. A duplicate root will cause a cartesian product

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
index d93953c..d3ccf33 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
@@ -46,6 +46,7 @@ import java.util.UUID;
 import javax.persistence.EntityManager;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.StackAccessException;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.spi.Resource;
@@ -92,6 +93,7 @@ import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.easymock.Capture;
 import org.easymock.EasyMock;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Rule;
 import org.junit.Test;
@@ -131,7 +133,7 @@ public class AmbariMetaInfoTest {
   private static final int PROPERTIES_CNT = 62;
   private static final int OS_CNT = 4;
 
-  private static AmbariMetaInfo metaInfo = null;
+  private static TestAmbariMetaInfo metaInfo = null;
   private final static Logger LOG =
       LoggerFactory.getLogger(AmbariMetaInfoTest.class);
   private static final String FILE_NAME = "hbase-site.xml";
@@ -157,6 +159,11 @@ public class AmbariMetaInfoTest {
     metaInfo = createAmbariMetaInfo(stacks, version);
   }
 
+  @AfterClass
+  public static void tearDown() throws Exception {
+    H2DatabaseCleaner.clearDatabase(metaInfo.injector.getProvider(EntityManager.class).get());
+  }
+
   public class MockModule extends AbstractModule {
     @Override
     protected void configure() {
@@ -2141,11 +2148,12 @@ public class AmbariMetaInfoTest {
     AlertDefinitionDAO alertDefinitionDAO;
     AlertDefinitionFactory alertDefinitionFactory;
     OsFamily osFamily;
+    Injector injector;
 
     public TestAmbariMetaInfo(Configuration configuration) throws Exception {
       super(configuration);
 
-      Injector injector = Guice.createInjector(Modules.override(
+      injector = Guice.createInjector(Modules.override(
           new InMemoryDefaultTestModule()).with(new MockModule()));
 
       injector.getInstance(GuiceJpaInitializer.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistKeyValueImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistKeyValueImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistKeyValueImplTest.java
index 63f269d..d6815fd 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistKeyValueImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistKeyValueImplTest.java
@@ -20,6 +20,7 @@ package org.apache.ambari.server.api.services;
 
 import java.util.Map;
 
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.junit.After;
@@ -29,7 +30,6 @@ import org.junit.Test;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
 
 
 public class PersistKeyValueImplTest extends Assert {
@@ -46,7 +46,7 @@ public class PersistKeyValueImplTest extends Assert {
 
   @After
   public void tearDown() throws Exception {
-    injector.getInstance(PersistService.class).stop();
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistServiceTest.java
index 7576501..57ccdb9 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistServiceTest.java
@@ -21,6 +21,7 @@ package org.apache.ambari.server.api.services;
 import java.io.IOException;
 import java.util.Map;
 
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.RandomPortJerseyTest;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
@@ -35,7 +36,6 @@ import org.junit.Test;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
 import com.sun.jersey.api.client.Client;
 import com.sun.jersey.api.client.UniformInterfaceException;
 import com.sun.jersey.api.client.WebResource;
@@ -80,7 +80,7 @@ public class PersistServiceTest extends RandomPortJerseyTest {
   @After
   public void tearDown() throws Exception {
     super.tearDown();
-    injector.getInstance(PersistService.class).stop();
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
index 6640837..3a93fbf 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
@@ -32,6 +32,7 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.agent.HeartbeatTestHelper;
 import org.apache.ambari.server.agent.RecoveryConfig;
 import org.apache.ambari.server.agent.RecoveryConfigHelper;
@@ -52,7 +53,6 @@ import com.google.common.eventbus.EventBus;
 import com.google.inject.Guice;
 import com.google.inject.Inject;
 import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
 
 /**
  * Test RecoveryConfigHelper class
@@ -87,7 +87,7 @@ public class RecoveryConfigHelperTest {
 
   @After
   public void teardown() throws Exception {
-    injector.getInstance(PersistService.class).stop();
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
index 8c87f0f..0f5a388 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.ambari.server.controller;
 
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -27,6 +28,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.ActionManager;
@@ -73,7 +75,6 @@ import org.springframework.security.core.context.SecurityContextHolder;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
 
 import junit.framework.Assert;
 
@@ -137,9 +138,9 @@ public class AmbariCustomCommandExecutionHelperTest {
   }
 
   @After
-  public void teardown() {
+  public void teardown() throws AmbariException, SQLException {
     SecurityContextHolder.getContext().setAuthentication(null);
-    injector.getInstance(PersistService.class).stop();
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index 6e2190b..af67f05 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -58,6 +58,7 @@ import javax.persistence.EntityManager;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ClusterNotFoundException;
 import org.apache.ambari.server.DuplicateResourceException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.HostNotFoundException;
 import org.apache.ambari.server.ObjectNotFoundException;
 import org.apache.ambari.server.ParentObjectNotFoundException;
@@ -171,7 +172,6 @@ import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
 
 import junit.framework.Assert;
 
@@ -241,6 +241,7 @@ public class AmbariManagementControllerTest {
     InMemoryDefaultTestModule module = new InMemoryDefaultTestModule();
     backingProperties = module.getProperties();
     injector = Guice.createInjector(module);
+    H2DatabaseCleaner.resetSequences(injector);
     injector.getInstance(GuiceJpaInitializer.class);
     ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
     ambariMetaInfo.init();
@@ -257,7 +258,7 @@ public class AmbariManagementControllerTest {
 
   @Before
   public void setup() throws Exception {
-    entityManager = injector.getInstance(EntityManager.class);
+    entityManager = injector.getProvider(EntityManager.class).get();
     actionDB = injector.getInstance(ActionDBAccessor.class);
     serviceFactory = injector.getInstance(ServiceFactory.class);
     serviceComponentFactory = injector.getInstance(
@@ -284,7 +285,7 @@ public class AmbariManagementControllerTest {
 
   @AfterClass
   public static void afterClass() throws Exception {
-    injector.getInstance(PersistService.class).stop();
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
   }
 
   private static String getUniqueName() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariServerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariServerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariServerTest.java
index ff5d1bf..85c47fc 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariServerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariServerTest.java
@@ -31,6 +31,7 @@ import java.net.InetAddress;
 import java.net.PasswordAuthentication;
 import java.sql.Connection;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.EnumSet;
@@ -41,6 +42,7 @@ import javax.servlet.DispatcherType;
 import javax.servlet.SessionCookieConfig;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.checks.DatabaseConsistencyCheckHelper;
 import org.apache.ambari.server.configuration.Configuration;
@@ -81,7 +83,8 @@ public class AmbariServerTest {
   }
 
   @After
-  public void teardown() throws AmbariException {
+  public void teardown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java
index 58f597f..30816a5 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java
@@ -19,6 +19,7 @@ package org.apache.ambari.server.controller;
 
 import static org.mockito.Matchers.any;
 
+import java.sql.SQLException;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -27,6 +28,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper;
 import org.apache.ambari.server.actionmanager.Request;
@@ -61,7 +63,6 @@ import org.springframework.security.core.context.SecurityContextHolder;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
 
 import junit.framework.Assert;
 
@@ -112,8 +113,8 @@ public class BackgroundCustomCommandExecutionTest {
     SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
   }
   @After
-  public void teardown() {
-    injector.getInstance(PersistService.class).stop();
+  public void teardown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
     SecurityContextHolder.getContext().setAuthentication(null);
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java
index a54fb98..0b4c81d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.controller;
 
+import java.sql.SQLException;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -25,6 +26,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.controller.internal.ComponentResourceProviderTest;
 import org.apache.ambari.server.controller.internal.ServiceResourceProviderTest;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
@@ -48,7 +50,6 @@ import org.springframework.security.core.context.SecurityContextHolder;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
 
 import junit.framework.Assert;
 
@@ -76,8 +77,8 @@ public class RefreshYarnCapacitySchedulerReleaseConfigTest {
   }
 
   @After
-  public void teardown() {
-    injector.getInstance(PersistService.class).stop();
+  public void teardown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
 
     // Clear the authenticated user
     SecurityContextHolder.getContext().setAuthentication(null);

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java
index 9fc51bd..e9b4aa7 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java
@@ -21,14 +21,18 @@ package org.apache.ambari.server.controller;
 import static junit.framework.Assert.assertEquals;
 import static junit.framework.Assert.assertTrue;
 
+import java.sql.SQLException;
 import java.util.Collections;
 import java.util.Set;
 
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.ObjectNotFoundException;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.RootServiceResponseFactory.Components;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -52,6 +56,11 @@ public class RootServiceResponseFactoryTest {
     injector.injectMembers(this);
   }
 
+  @After
+  public void teardown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
+  }
+
   @Test
   public void testGetRootServices() throws Exception {
     // Request a null service name

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActionResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActionResourceProviderTest.java
index e29c047..061f06a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActionResourceProviderTest.java
@@ -24,12 +24,14 @@ import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
 
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.actionmanager.ActionType;
 import org.apache.ambari.server.actionmanager.TargetHostType;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
@@ -52,7 +54,6 @@ import org.junit.Test;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
 
 public class ActionResourceProviderTest {
 
@@ -84,8 +85,8 @@ public class ActionResourceProviderTest {
   }
 
   @After
-  public void teardown() {
-    injector.getInstance(PersistService.class).stop();
+  public void teardown() throws AmbariException, SQLException {
+    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java
index 9f6591c..4b2bb7a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java
@@ -735,8 +735,8 @@ public class AlertResourceProviderTest {
 
       expect(configuration.getDatabaseUrl()).andReturn(JDBC_IN_MEMORY_URL).anyTimes();
       expect(configuration.getDatabaseDriver()).andReturn(JDBC_IN_MEMORY_DRIVER).anyTimes();
-      expect(configuration.getDatabaseUser()).andReturn("test").anyTimes();
-      expect(configuration.getDatabasePassword()).andReturn("test").anyTimes();
+      expect(configuration.getDatabaseUser()).andReturn("sa").anyTimes();
+      expect(configuration.getDatabasePassword()).andReturn("").anyTimes();
       expect(configuration.getAlertEventPublisherPoolSize()).andReturn(Integer.valueOf(Configuration.ALERTS_EXECUTION_SCHEDULER_THREADS.getDefaultValue())).anyTimes();
       expect(configuration.getMasterKeyLocation()).andReturn(new File("/test")).anyTimes();
       expect(configuration.getTemporaryKeyStoreRetentionMinutes()).andReturn(2l).anyTimes();

http://git-wip-us.apache.org/repos/asf/ambari/blob/3a7906c8/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java
index a96f395..cd2f99e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java
@@ -34,6 +34,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javax.persistence.EntityManager;
+
+import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.ExecutionCommandWrapperFactory;
@@ -46,6 +49,7 @@ import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.dao.HostRoleCommandStatusSummaryDTO;
 import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
 import org.apache.ambari.server.orm.entities.StageEntity;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -82,6 +86,10 @@ public class CalculatedStatusTest {
     s_field.setAccessible(true);
   }
 
+  @After
+  public void after() throws Exception {
+    H2DatabaseCleaner.clearDatabase(m_injector.getProvider(EntityManager.class).get());
+  }
 
   @Test
   public void testGetStatus() throws Exception {


Mime
View raw message