Skip to content

Commit

Permalink
Add integration test that demonstrates Transaction API bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Woods committed Dec 27, 2013
1 parent 56e3fc3 commit c3e5448
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 7 deletions.
Expand Up @@ -62,12 +62,11 @@ public void setLogger() {
protected static final String serverAddress = "http://" + HOSTNAME + ":" +
SERVER_PORT + "/";

protected static HttpClient client;
protected static HttpClient client = createClient();

static {
client =
HttpClientBuilder.create().setMaxConnPerRoute(MAX_VALUE)
.setMaxConnTotal(MAX_VALUE).build();
protected static HttpClient createClient() {
return HttpClientBuilder.create().setMaxConnPerRoute(MAX_VALUE)
.setMaxConnTotal(MAX_VALUE).build();
}

protected static HttpPost postObjMethod(final String pid) {
Expand Down
Expand Up @@ -32,6 +32,7 @@
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.junit.Ignore;
import org.junit.Test;

import com.hp.hpl.jena.graph.Node;
Expand Down Expand Up @@ -147,7 +148,6 @@ public void testCreateDoStuffAndRollbackTransaction() throws Exception {
@Test
public void testCreateDoStuffAndCommitTransaction() throws Exception {
/* create a tx */

final String objectInTxCommit = randomUUID().toString();

final HttpPost createTx = new HttpPost(serverAddress + "fcr:tx");
Expand Down Expand Up @@ -181,7 +181,7 @@ public void testCreateDoStuffAndCommitTransaction() throws Exception {
"Expected to not find our object within the scope of the transaction",
404, resp.getStatusLine().getStatusCode());

/* and rollback */
/* and commit */
final HttpPost commitTx =
new HttpPost(txLocation + "/fcr:tx/fcr:commit");
resp = execute(commitTx);
Expand All @@ -199,4 +199,64 @@ public void testCreateDoStuffAndCommitTransaction() throws Exception {

}

@Ignore("Until ticket is resolved: https://www.pivotaltracker.com/story/show/63029852")
@Test
public void testCreateDoStuffAndCommitTransactionSeparateConnections() throws Exception {
/* create a tx */
final String objectInTxCommit = randomUUID().toString();

final HttpPost createTx = new HttpPost(serverAddress + "fcr:tx");

final HttpResponse response = execute(createTx);
assertEquals(201, response.getStatusLine().getStatusCode());

final String txLocation =
response.getFirstHeader("Location").getValue();

/* create a new object inside the tx */
client = createClient();
final HttpPost postNew =
new HttpPost(txLocation + "/" + objectInTxCommit);
HttpResponse resp = execute(postNew);
assertEquals(201, resp.getStatusLine().getStatusCode());

/* fetch the created tx from the endpoint */
client = createClient();
final HttpGet getTx = new HttpGet(txLocation + "/" + objectInTxCommit);
GraphStore graphStore = getGraphStore(getTx);

logger.debug(graphStore.toString());

assertTrue(graphStore.toDataset().asDatasetGraph().contains(ANY,
createURI(txLocation + "/" + objectInTxCommit), ANY, ANY));

/* fetch the object-in-tx outside of the tx */
client = createClient();
final HttpGet getObj =
new HttpGet(serverAddress + objectInTxCommit);
resp = execute(getObj);
assertEquals(
"Expected to not find our object within the scope of the transaction",
404, resp.getStatusLine().getStatusCode());

/* and commit */
client = createClient();
final HttpPost commitTx =
new HttpPost(txLocation + "/fcr:tx/fcr:commit");
resp = execute(commitTx);

assertEquals(204, resp.getStatusLine().getStatusCode());

/* fetch the object-in-tx outside of the tx after it has been committed */
client = createClient();
final HttpGet getObjCommitted =
new HttpGet(serverAddress + objectInTxCommit);
graphStore = getGraphStore(getObjCommitted);

assertTrue("Expected to find our object after the transaction was committed",
graphStore.toDataset().asDatasetGraph()
.contains(ANY, createURI(serverAddress + objectInTxCommit), ANY, ANY));

}

}

0 comments on commit c3e5448

Please sign in to comment.