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());
}
}
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)) {
}
}
}
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.");
}
}
}
}
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.");
}
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;
}
Aggregations