Skip to content

Commit

Permalink
Bug# 478635 - Fixed failures in dynamic entities tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Kraus <[email protected]>
Reviewed-by: Lukas Jungmann <[email protected]>
  • Loading branch information
Tomas-Kraus committed Oct 2, 2015
1 parent fcfc5f9 commit 100e361
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 24 deletions.
4 changes: 2 additions & 2 deletions jpa/eclipselink.jpa.test/antbuild.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1643,8 +1643,6 @@
<param name="RUN_PATH" value="run.weaver.classpath"/>
<param name="DB_URL" value="${db.url}"/>
</antcall>
<!--
unstable on (public) hudson, needs to be stabilized first
<antcall target="run-test" inheritRefs="true">
<param name="TEST_CLASS" value="org.eclipse.persistence.testing.tests.jpa.dynamic.AllTests"/>
<param name="TEST_AGENT" value="${test.agent}"/>
Expand All @@ -1654,6 +1652,8 @@
<param name="RUN_PATH" value="run.extended.classpath"/>
<param name="DB_URL" value="${db.url}"/>
</antcall>
<!--
unstable on (public) hudson, needs to be stabilized first
<antcall target="test-remote-jpa" inheritRefs="true"/>
-->
<antcall target="run-bean-validation-tests" inheritRefs="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,29 @@
******************************************************************************/
package org.eclipse.persistence.testing.tests.jpa.dynamic.employee;

//javase imports
import static org.eclipse.persistence.logging.SessionLog.FINE;
import static org.eclipse.persistence.logging.SessionLog.WARNING;
import static org.eclipse.persistence.testing.tests.jpa.dynamic.DynamicTestHelper.DYNAMIC_PERSISTENCE_NAME;
import static org.junit.Assert.assertEquals;

//java eXtension imports
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

//JUnit4 imports
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;

//EclipseLink imports
import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.dynamic.DynamicType;
import org.eclipse.persistence.exceptions.DatabaseException;
import org.eclipse.persistence.internal.queries.EntityFetchGroup;
import org.eclipse.persistence.jpa.JpaHelper;
import org.eclipse.persistence.jpa.dynamic.JPADynamicHelper;
import org.eclipse.persistence.logging.SessionLog;
import org.eclipse.persistence.queries.FetchGroupTracker;
import org.eclipse.persistence.sessions.server.Server;

//domain (testing) imports
import org.eclipse.persistence.testing.tests.jpa.config.ConfigPUTestSuite;
import org.eclipse.persistence.testing.tests.jpa.dynamic.DynamicTestHelper;
import org.eclipse.persistence.testing.tests.jpa.dynamic.QuerySQLTracker;
import static org.eclipse.persistence.testing.tests.jpa.dynamic.DynamicTestHelper.DYNAMIC_PERSISTENCE_NAME;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class EmployeeSparseMergeTestSuite {

Expand All @@ -51,20 +47,62 @@ public class EmployeeSparseMergeTestSuite {
static Server serverSession = null;
static DynamicEmployeeSystem deSystem = null;
static QuerySQLTracker qTracker = null;
private static SessionLog log = null;

/**
* {@code SEQ_COUNT} sequence clean up (initialize it to {@code 0} value) SQL statement call.
* @param serverSession Current server session.
* @throws DatabaseException when sequence does not exist.
*/
private static void runCleanSequence(final Server serverSession) throws DatabaseException {
if (serverSession.getPlatform().isMySQL()) {
serverSession.executeNonSelectingSQL("UPDATE EMPLOYEE_SEQ SET SEQ_COUNT = 0 WHERE SEQ_NAME = 'EMP_SEQ'");
} else {
serverSession.executeNonSelectingSQL("UPDATE SEQUENCE SET SEQ_COUNT = 0 WHERE SEQ_NAME = 'EMP_SEQ'");
}
}

/**
* {@code SEQ_COUNT} sequence initialization.
* @param serverSession Current server session.
* @throws DatabaseException when sequence initialization failed.
*/
private static void initSequence(final Server serverSession) throws DatabaseException {
boolean retry = false;
// This may pass if SEQ_COUNT already exists.
try {
runCleanSequence(serverSession);
log.log(FINE, "SEQ_COUNT sequence already exists and was cleaned up.");
} catch (DatabaseException ex) {
log.log(FINE, "SEQ_COUNT 1st sequence cleanup attempt failed: " + ex.getMessage());
retry = true;
}
// SEQ_COUNT does not exist so it must be created before clean up.
if (retry) {
// Test suite depends on SEQ_COUNT which is part of common JPA tests.
log.log(FINE, "Running SEQ_COUNT sequence initialization.");
ConfigPUTestSuite suite = new ConfigPUTestSuite();
suite.setUp();
suite.testCreateConfigPU();
suite.testVerifyConfigPU();
try {
runCleanSequence(serverSession);
log.log(FINE, "SEQ_COUNT sequence cleaned up after being created.");
} catch (DatabaseException ex) {
log.log(WARNING, "SEQ_COUNT sequence cleanup failed after initialization: " + ex.getMessage());
throw ex;
}
}
}

@BeforeClass
public static void setUp() throws Exception {
emf = DynamicTestHelper.createEMF(DYNAMIC_PERSISTENCE_NAME);
helper = new JPADynamicHelper(emf);
deSystem = DynamicEmployeeSystem.buildProject(helper);
serverSession = JpaHelper.getServerSession(emf);
if (serverSession.getPlatform().isMySQL()) {
serverSession.executeNonSelectingSQL(
"UPDATE EMPLOYEE_SEQ SET SEQ_COUNT = 0 WHERE SEQ_NAME = 'EMP_SEQ'");
} else {
serverSession.executeNonSelectingSQL(
"UPDATE SEQUENCE SET SEQ_COUNT = 0 WHERE SEQ_NAME = 'EMP_SEQ'");
}
log = serverSession.getSessionLog();
initSequence(serverSession);
deSystem.populate(helper, emf.createEntityManager());
serverSession.getIdentityMapAccessor().initializeAllIdentityMaps();
qTracker = QuerySQLTracker.install(serverSession);
Expand Down Expand Up @@ -93,6 +131,7 @@ public static void tearDown() {
helper = null;
emf.close();
emf = null;
log = null;
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void initTable() {
final EntityTransaction et = em.getTransaction();
et.begin();
try {
em.createNativeQuery("CREATE TABLE SIMPLE_TYPE_1 (SID INT, VAL_1 VARCHAR(15), VAL_2 BOOLEAN)").executeUpdate();
em.createNativeQuery("CREATE TABLE SIMPLE_TYPE_1 (SID INTEGER, VAL_1 VARCHAR(15))").executeUpdate();
et.commit();
} catch (Exception ex) {
log.log(WARNING, "Could not create SIMPLE_TYPE_1 table: ." + ex.getMessage());
Expand All @@ -98,7 +98,7 @@ public void destroyTable() {
final EntityTransaction et = em.getTransaction();
et.begin();
try {
em.createNativeQuery("DROP TABLE SIMPLE_TYPE").executeUpdate();
em.createNativeQuery("DROP TABLE SIMPLE_TYPE_1").executeUpdate();
et.commit();
} catch (Exception ex) {
log.log(WARNING, "Could not drop SIMPLE_TYPE_1 table: ." + ex.getMessage());
Expand Down

0 comments on commit 100e361

Please sign in to comment.