Search in sources :

Example 11 with TestProblemException

use of org.eclipse.persistence.testing.framework.TestProblemException in project eclipselink by eclipse-ee4j.

the class RMIServerManagerController method start.

public static void start(Session session, String nameToBind, String controllerClassName) {
    System.out.println("The following environment properties must be set to run this test.");
    System.out.println("-Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory -Djava.naming.provider.url=iiop://localhost:900");
    System.out.println("The follwing corba naming server must also be started on the computer.");
    System.out.println("<java_home>/bin/tnameserv.exe");
    RMIServerManagerController manager = null;
    Context initialNamingContext = null;
    try {
        initialNamingContext = new InitialContext();
    } catch (NamingException exception) {
        System.out.println("Naming Exception " + exception.toString());
    }
    // Set the security manager
    try {
        System.setSecurityManager(new RMISecurityManager());
    } catch (Exception exception) {
        System.out.println("Security violation 1" + exception.toString());
    }
    // Make sure RMI registry is started.
    try {
        java.rmi.registry.LocateRegistry.createRegistry(1099);
    } catch (Exception exception) {
        System.out.println("Security violation 2" + exception.toString());
    }
    // Create local instance of the factory
    try {
        manager = new RMIServerManagerController(session, controllerClassName);
    } catch (RemoteException exception) {
        throw new TestProblemException("Corba not configured correctly, see system.out", exception);
    }
    // Put the local instance into the Registry
    try {
        initialNamingContext.unbind(nameToBind);
    } catch (Exception exception) {
        System.out.println("Security violation " + exception.toString());
    }
    // Put the local instance into the Registry
    try {
        initialNamingContext.rebind(nameToBind, manager);
    } catch (Exception exception) {
        throw new TestProblemException("Corba not configured correctly, see system.out", exception);
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) NamingException(javax.naming.NamingException) RMISecurityManager(java.rmi.RMISecurityManager) RemoteException(java.rmi.RemoteException) InitialContext(javax.naming.InitialContext) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) NamingException(javax.naming.NamingException) RemoteException(java.rmi.RemoteException)

Example 12 with TestProblemException

use of org.eclipse.persistence.testing.framework.TestProblemException in project eclipselink by eclipse-ee4j.

the class BroadcastSetupHelper method stopCacheSynchronization.

public void stopCacheSynchronization(AbstractSession session) {
    try {
        sessions.remove(session);
        getEventLock().detach(session);
        session.setShouldPropagateChanges(false);
        session.getCommandManager().shutdown();
        session.setCommandManager(null);
        if (sessions.size() == 0) {
            // destroy the factory
            destroyFactory();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new TestProblemException("exception in stopCacheSynchronization ", ex);
    }
}
Also used : TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) NamingException(javax.naming.NamingException)

Example 13 with TestProblemException

use of org.eclipse.persistence.testing.framework.TestProblemException in project eclipselink by eclipse-ee4j.

the class SybaseTransactionIsolationListener method isDatabaseVersionSupported.

// verify that it's version 15 or higher - this doesn't work with version 12.5
public static boolean isDatabaseVersionSupported(ServerSession serverSession) {
    DatabaseAccessor accessor = (DatabaseAccessor) serverSession.allocateReadConnection();
    int version;
    try {
        String strVersion = accessor.getConnectionMetaData().getDatabaseProductVersion();
        int iStart = strVersion.indexOf("/") + 1;
        int iEnd = strVersion.indexOf(".");
        String strIntVersion = strVersion.substring(iStart, iEnd);
        version = Integer.parseInt(strIntVersion);
    } catch (SQLException ex) {
        throw new TestProblemException("failed to obtain database version number", ex);
    }
    return version >= requiredVersion;
}
Also used : SQLException(java.sql.SQLException) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) DatabaseAccessor(org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor)

Example 14 with TestProblemException

use of org.eclipse.persistence.testing.framework.TestProblemException in project eclipselink by eclipse-ee4j.

the class SybaseTransactionIsolationListener method postAcquireConnection.

@Override
public void postAcquireConnection(SessionEvent event) {
    Connection conn = ((DatabaseAccessor) event.getResult()).getConnection();
    Statement stmt1 = null;
    Statement stmt2 = null;
    ResultSet result = null;
    Integer isolationLevel;
    try {
        stmt1 = conn.createStatement();
        result = stmt1.executeQuery("select @@isolation");
        result.next();
        isolationLevel = result.getInt(1);
        if (isolationLevel > 0) {
            // If conn1 began transaction and updated the row (but hasn't committed the transaction yet),
            // then conn2 should be able to read the original (not updated) state of the row.
            // Without this conn2 reading the row hangs on Sybase.
            stmt2 = conn.createStatement();
            stmt2.execute("set transaction isolation level 0");
            stmt2.close();
            connections.put(conn, isolationLevel);
        }
    } catch (SQLException sqlException) {
        throw new TestProblemException("postAcquireConnection failed. ", sqlException);
    } finally {
        if (result != null) {
            try {
                result.close();
            } catch (SQLException ex) {
            // Ignore
            }
        }
        if (stmt1 != null) {
            try {
                stmt1.close();
            } catch (SQLException ex) {
            // Ignore
            }
        }
        if (stmt2 != null) {
            try {
                stmt2.close();
            } catch (SQLException ex) {
            // Ignore
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) DatabaseAccessor(org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor)

Example 15 with TestProblemException

use of org.eclipse.persistence.testing.framework.TestProblemException in project eclipselink by eclipse-ee4j.

the class SybaseTransactionIsolationListener method preReleaseConnection.

@Override
public void preReleaseConnection(SessionEvent event) {
    Connection conn = ((DatabaseAccessor) event.getResult()).getConnection();
    Statement stmt = null;
    try {
        Integer isolationLevel = connections.remove(conn);
        if (isolationLevel != null) {
            // reset the original transaction isolation.
            stmt = conn.createStatement();
            stmt.execute("set transaction isolation level " + isolationLevel);
            stmt.close();
        }
    } catch (SQLException sqlException) {
        throw new TestProblemException("preReleaseConnection failed. ", sqlException);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException ex) {
            // Ignore
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) Connection(java.sql.Connection) DatabaseAccessor(org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor)

Aggregations

TestProblemException (org.eclipse.persistence.testing.framework.TestProblemException)48 TestSetup (junit.extensions.TestSetup)18 TestSuite (junit.framework.TestSuite)18 PersistenceProvider (jakarta.persistence.spi.PersistenceProvider)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 SQLException (java.sql.SQLException)4 Vector (java.util.Vector)3 NamingException (javax.naming.NamingException)3 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)3 DatabaseAccessor (org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor)3 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)3 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)3 TestWarningException (org.eclipse.persistence.testing.framework.TestWarningException)3 RMISecurityManager (java.rmi.RMISecurityManager)2 RemoteException (java.rmi.RemoteException)2 Connection (java.sql.Connection)2 Statement (java.sql.Statement)2 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)2 Expression (org.eclipse.persistence.expressions.Expression)2