final URI id2 = createId("blobClosedConn2");
// test con.isClosed() and idempotence of con.close()
runTests(new Action() {
public void run(Transaction txn) throws Exception {
BlobStoreConnection con = store.openConnection(txn, null);
assertFalse(con.isClosed());
con.close();
assertTrue(con.isClosed());
con.close();
assertTrue(con.isClosed());
con.close();
assertTrue(con.isClosed());
}
});
// test connection operations on a closed connection
runTests(new Action() {
public void run(Transaction txn) throws Exception {
final BlobStoreConnection con = store.openConnection(txn, null);
for (int idx = 0; idx < 3; idx++) {
con.close();
assertTrue(con.isClosed());
assertEquals(con.getBlobStore(), store);
shouldFail(new ERunnable() {
@Override
public void erun() throws Exception {
con.getBlob(id1, null);
}
}, IllegalStateException.class, null);
shouldFail(new ERunnable() {
@Override
public void erun() throws Exception {
con.getBlob(null, null);
}
}, IllegalStateException.class, null);
shouldFail(new ERunnable() {
@Override
public void erun() throws Exception {
con.getBlob(new ByteArrayInputStream(new byte[0]), -1, null);
}
}, IllegalStateException.class, null);
if (isListIdsSupp) {
shouldFail(new ERunnable() {
@Override
public void erun() throws Exception {
con.listBlobIds("foo");
}
}, IllegalStateException.class, null);
shouldFail(new ERunnable() {
@Override
public void erun() throws Exception {
con.listBlobIds(null);
}
}, IllegalStateException.class, null);
}
if (isSyncSupp) {
shouldFail(new ERunnable() {
@Override
public void erun() throws Exception {
con.sync();
}
}, IllegalStateException.class, null);
}
}
}
});
// test non-existent blob operations on a closed connection
runTests(new Action() {
public void run(Transaction txn) throws Exception {
final BlobStoreConnection con = store.openConnection(txn, null);
final Blob b = getBlob(con, id1, false);
for (int idx = 0; idx < 3; idx++) {
con.close();
assertTrue(con.isClosed());
assertEquals(b.getConnection(), con);
assertEquals(b.getId(), id1);
if (isOutputSupp) {
shouldFail(new ERunnable() {
@Override
public void erun() throws Exception {
b.openOutputStream(-1, true);
}
}, IllegalStateException.class, null);
}
shouldFail(new ERunnable() {
@Override
public void erun() throws Exception {
b.exists();
}
}, IllegalStateException.class, null);
}
}
});
// test existing blob operations on a closed connection
runTests(new Action() {
public void run(Transaction txn) throws Exception {
final BlobStoreConnection con = store.openConnection(txn, null);
final Blob b = getBlob(con, id1, false);
final Blob b2 = getBlob(con, id2, false);
createBlob(con, b, "foo");
for (int idx = 0; idx < 3; idx++) {
con.close();
assertTrue(con.isClosed());
assertEquals(b.getConnection(), con);
assertEquals(b.getId(), id1);
shouldFail(new ERunnable() {