Search in sources :

Example 1 with Accessor

use of org.eclipse.persistence.internal.databaseaccess.Accessor in project eclipselink by eclipse-ee4j.

the class SessionIsConnectedFlagTest method test.

@Override
public void test() {
    if (!getSession().isDatabaseSession()) {
        throwWarning("Test is designed to be run with DatabaseSession");
    }
    DatabaseSession session = (DatabaseSession) getSession();
    // session needs to be verified as connected
    assertTrue("Session isConnected should be true before logout", session.isConnected());
    // test session's accessors
    for (Accessor accessor : ((DatabaseSessionImpl) session).getAccessors()) {
        assertTrue(accessor.isConnected());
    }
    // logout session and test that the isConnected flag is false
    session.logout();
    assertFalse("Session isConnected should be false after logout", session.isConnected());
    // test session's accessors
    for (Accessor accessor : ((DatabaseSessionImpl) session).getAccessors()) {
        assertFalse(accessor.isConnected());
    }
    // login session and test that the isConnected flag is true
    session.login();
    assertTrue("Session isConnected should be true after login", session.isConnected());
    // test session's accessors
    for (Accessor accessor : ((DatabaseSessionImpl) session).getAccessors()) {
        assertTrue(accessor.isConnected());
    }
}
Also used : DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) Accessor(org.eclipse.persistence.internal.databaseaccess.Accessor)

Example 2 with Accessor

use of org.eclipse.persistence.internal.databaseaccess.Accessor in project eclipselink by eclipse-ee4j.

the class ClientServerTest method verify.

@Override
public void verify() {
    try {
        int counter = 0;
        ConnectionPool pool = server.serverSession.getConnectionPools().get("default");
        List<Accessor> connections = pool.getConnectionsAvailable();
        for (Iterator<Accessor> iterator = connections.iterator(); iterator.hasNext(); ) {
            if (iterator.next().isConnected()) {
                counter = counter + 1;
            }
        }
        if (counter < minimumConnections) {
            throw new TestErrorException("too many connections are disconnected!!");
        }
        if (counter > minimumConnections) {
            throw new TestErrorException("not enough connections are disconected!!");
        }
        if (connections.size() < minimumConnections) {
            throw new TestErrorException("too many connections are released!!");
        }
        if (connections.size() > minimumConnections) {
            throw new TestErrorException("not enough connections are released!!");
        }
    } catch (Exception ex) {
        if ((ex instanceof ValidationException) && (((ValidationException) ex).getErrorCode() == 7090)) {
        }
    }
}
Also used : ConnectionPool(org.eclipse.persistence.sessions.server.ConnectionPool) ValidationException(org.eclipse.persistence.exceptions.ValidationException) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) DatabaseAccessor(org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor) Accessor(org.eclipse.persistence.internal.databaseaccess.Accessor) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) ValidationException(org.eclipse.persistence.exceptions.ValidationException)

Example 3 with Accessor

use of org.eclipse.persistence.internal.databaseaccess.Accessor in project eclipselink by eclipse-ee4j.

the class ConnectionPoolFailoverTest method connectionPoolFailureTest.

@Test
public void connectionPoolFailureTest() {
    List<Accessor> connections = new ArrayList<>();
    // prime connection pools.
    for (int i = 0; i < 10; ++i) {
        connections.add(getEmulatedSession().getConnectionPool("default").acquireConnection());
    }
    for (Accessor accessor : connections) {
        getEmulatedSession().getConnectionPool("default").releaseConnection(accessor);
    }
    List<Accessor> list = getEmulatedSession().getReadConnectionPool().getConnectionsAvailable();
    for (Accessor accessor : list) {
        ((EmulatedConnection) accessor.getConnection()).causeCommError();
    }
    for (int i = 0; i < 4; ++i) {
        try {
            getEmulatedSession().acquireClientSession().readObject(Address.class);
        } catch (DatabaseException ex) {
            Assert.fail("Should have reconnected an not thrown exception.");
        }
    }
    connections = new ArrayList<Accessor>();
    // prime connection pools.
    for (int i = 0; i < 10; ++i) {
        connections.add(getEmulatedSession().getConnectionPool("default").acquireConnection());
    }
    for (Accessor accessor : connections) {
        getEmulatedSession().getConnectionPool("default").releaseConnection(accessor);
    }
    list = getEmulatedSession().getReadConnectionPool().getConnectionsAvailable();
    for (Accessor accessor : list) {
        ((EmulatedConnection) accessor.getConnection()).causeCommError();
    }
    for (int i = 0; i < 4; ++i) {
        try {
            ReadObjectQuery query = new ReadObjectQuery(Address.class);
            query.setQueryTimeout(10000);
            getEmulatedSession().acquireClientSession().executeQuery(query);
        } catch (DatabaseException ex) {
            if (i != 0) {
                Assert.fail("Should have reconnected and not thrown exception.");
            }
        }
    }
}
Also used : EmulatedConnection(org.eclipse.persistence.testing.tests.junit.failover.emulateddriver.EmulatedConnection) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) ArrayList(java.util.ArrayList) Accessor(org.eclipse.persistence.internal.databaseaccess.Accessor) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException) Test(org.junit.Test)

Example 4 with Accessor

use of org.eclipse.persistence.internal.databaseaccess.Accessor in project eclipselink by eclipse-ee4j.

the class ConnectionPoolFailoverTest method fullDatabaseFailureTest.

@Test
public void fullDatabaseFailureTest() {
    try {
        List<Accessor> list = getEmulatedSession().getReadConnectionPool().getConnectionsAvailable();
        for (Accessor accessor : list) {
            ((EmulatedConnection) accessor.getConnection()).causeCommError();
        }
        EmulatedDriver.fullFailure = true;
        getEmulatedSession().acquireClientSession().readObject(Address.class);
    } catch (DatabaseException ex) {
        // Exception expected
        return;
    } finally {
        EmulatedDriver.fullFailure = false;
    }
    Assert.fail("Should have thrown exception as database connection is unavailable.");
}
Also used : EmulatedConnection(org.eclipse.persistence.testing.tests.junit.failover.emulateddriver.EmulatedConnection) Accessor(org.eclipse.persistence.internal.databaseaccess.Accessor) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException) Test(org.junit.Test)

Example 5 with Accessor

use of org.eclipse.persistence.internal.databaseaccess.Accessor in project eclipselink by eclipse-ee4j.

the class AbstractSession method getAccessors.

/**
 * INTERNAL:
 * Return the connections to use for the query execution.
 */
public Collection<Accessor> getAccessors(Call call, AbstractRecord translationRow, DatabaseQuery query) {
    // Check for partitioning.
    Collection<Accessor> accessors = null;
    if (query.getPartitioningPolicy() != null) {
        accessors = query.getPartitioningPolicy().getConnectionsForQuery(this, query, translationRow);
        if (accessors != null) {
            return accessors;
        }
    }
    ClassDescriptor descriptor = query.getDescriptor();
    if ((descriptor != null) && (descriptor.getPartitioningPolicy() != null)) {
        accessors = descriptor.getPartitioningPolicy().getConnectionsForQuery(this, query, translationRow);
        if (accessors != null) {
            return accessors;
        }
    }
    if (this.partitioningPolicy != null) {
        accessors = this.partitioningPolicy.getConnectionsForQuery(this, query, translationRow);
        if (accessors != null) {
            return accessors;
        }
    }
    return accessors;
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Accessor(org.eclipse.persistence.internal.databaseaccess.Accessor)

Aggregations

Accessor (org.eclipse.persistence.internal.databaseaccess.Accessor)26 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)8 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)7 ServerSession (org.eclipse.persistence.sessions.server.ServerSession)5 ArrayList (java.util.ArrayList)4 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)4 SQLException (java.sql.SQLException)3 DatabaseTable (org.eclipse.persistence.internal.helper.DatabaseTable)3 ConnectionPool (org.eclipse.persistence.sessions.server.ConnectionPool)3 EntityManager (jakarta.persistence.EntityManager)2 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 OracleConnection (oracle.jdbc.OracleConnection)2 ValidationException (org.eclipse.persistence.exceptions.ValidationException)2 DatabaseAccessor (org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor)2 DatabaseCall (org.eclipse.persistence.internal.databaseaccess.DatabaseCall)2 DatasourceCall (org.eclipse.persistence.internal.databaseaccess.DatasourceCall)2 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)2