Skip to content

get stream transactions #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/Drivers/Java/Reference/Database/StreamTransactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ Gets information about a Stream Transaction.
transaction id


## ArangoDatabase.getStreamTransactions

`ArangoDatabase.getStreamTransactions() : Collection<TransactionEntity>`

Gets all the currently running Stream Transactions.


## ArangoDatabase.commitStreamTransaction

`ArangoDatabase.commitStreamTransaction(String id) : StreamTransactionEntity`
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/arangodb/ArangoDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,17 @@ GraphEntity createGraph(String name, Collection<EdgeDefinition> edgeDefinitions,
*/
StreamTransactionEntity getStreamTransaction(String id) throws ArangoDBException;

/**
* Gets all the currently running Stream Transactions.
*
* @return all the currently running Stream Transactions
* @throws ArangoDBException
* @see <a href="https://docs.arangodb.com/current/HTTP/transaction-stream-transaction.html#list-currently-ongoing-transactions">
* API Documentation</a>
* @since ArangoDB 3.5.0
*/
Collection<TransactionEntity> getStreamTransactions() throws ArangoDBException;

/**
* Commits a Stream Transaction.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ public class StreamTransactionEntity implements Entity {
private String id;
private StreamTransactionStatus status;

public enum StreamTransactionStatus {
running, committed, aborted
}

public String getId() {
return id;
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/arangodb/entity/StreamTransactionStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* DISCLAIMER
*
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright holder is ArangoDB GmbH, Cologne, Germany
*/

package com.arangodb.entity;

/**
* @author Michele Rastelli
*/
public enum StreamTransactionStatus {
running, committed, aborted
}
42 changes: 42 additions & 0 deletions src/main/java/com/arangodb/entity/TransactionEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* DISCLAIMER
*
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright holder is ArangoDB GmbH, Cologne, Germany
*/

package com.arangodb.entity;

/**
* @author Michele Rastelli
* @see <a href=
* "https://docs.arangodb.com/current/HTTP/transaction-stream-transaction.html#list-currently-ongoing-transactions</a>
* @since ArangoDB 3.5.0
*/
public class TransactionEntity implements Entity {

private String id;
private StreamTransactionStatus state;

public String getId() {
return id;
}

public StreamTransactionStatus getStatus() {
return state;
}

}
5 changes: 5 additions & 0 deletions src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ public StreamTransactionEntity getStreamTransaction(String id) throws ArangoDBEx
return executor.execute(getStreamTransactionRequest(id), streamTransactionResponseDeserializer());
}

@Override
public Collection<TransactionEntity> getStreamTransactions() throws ArangoDBException {
return executor.execute(getStreamTransactionsRequest(), transactionsResponseDeserializer());
}

@Override
public StreamTransactionEntity commitStreamTransaction(String id) throws ArangoDBException {
return executor.execute(commitStreamTransactionRequest(id), streamTransactionResponseDeserializer());
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/arangodb/internal/InternalArangoDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,25 @@ protected Request abortStreamTransactionRequest(String id) {
return request(name, RequestType.DELETE, PATH_API_TRANSACTION, id);
}

protected Request getStreamTransactionsRequest() {
return request(name, RequestType.GET, PATH_API_TRANSACTION);
}

protected Request getStreamTransactionRequest(String id) {
return request(name, RequestType.GET, PATH_API_TRANSACTION, id);
}

protected ResponseDeserializer<Collection<TransactionEntity>> transactionsResponseDeserializer() {
return new ResponseDeserializer<Collection<TransactionEntity>>() {
@Override
public Collection<TransactionEntity> deserialize(final Response response) throws VPackException {
final VPackSlice result = response.getBody().get("transactions");
return util().deserialize(result, new Type<Collection<TransactionEntity>>() {
}.getType());
}
};
}

protected Request commitStreamTransactionRequest(String id) {
return request(name, RequestType.PUT, PATH_API_TRANSACTION, id);
}
Expand Down
29 changes: 25 additions & 4 deletions src/test/java/com/arangodb/StreamTransactionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void beginStreamTransaction() {

StreamTransactionEntity tx = db.beginStreamTransaction(null);
assertThat(tx.getId(), is(notNullValue()));
assertThat(tx.getStatus(), is(StreamTransactionEntity.StreamTransactionStatus.running));
assertThat(tx.getStatus(), is(StreamTransactionStatus.running));
db.abortStreamTransaction(tx.getId());
}

Expand All @@ -97,7 +97,7 @@ public void abortStreamTransaction() {

assertThat(abortedTx.getId(), is(notNullValue()));
assertThat(abortedTx.getId(), is(begunTx.getId()));
assertThat(abortedTx.getStatus(), is(StreamTransactionEntity.StreamTransactionStatus.aborted));
assertThat(abortedTx.getStatus(), is(StreamTransactionStatus.aborted));
}

@Test
Expand Down Expand Up @@ -151,7 +151,7 @@ public void getStreamTransaction() {

assertThat(gotTx.getId(), is(notNullValue()));
assertThat(gotTx.getId(), is(createdTx.getId()));
assertThat(gotTx.getStatus(), is(StreamTransactionEntity.StreamTransactionStatus.running));
assertThat(gotTx.getStatus(), is(StreamTransactionStatus.running));

db.abortStreamTransaction(createdTx.getId());
}
Expand Down Expand Up @@ -185,7 +185,7 @@ public void commitStreamTransaction() {

assertThat(committedTx.getId(), is(notNullValue()));
assertThat(committedTx.getId(), is(createdTx.getId()));
assertThat(committedTx.getStatus(), is(StreamTransactionEntity.StreamTransactionStatus.committed));
assertThat(committedTx.getStatus(), is(StreamTransactionStatus.committed));
}

@Test
Expand Down Expand Up @@ -705,4 +705,25 @@ public void nextCursor() {
db.abortStreamTransaction(tx.getId());
}

@Test
public void getStreamTransactions() {
assumeTrue(requireSingleServer());
assumeTrue(requireVersion(3, 5));
assumeTrue(requireStorageEngine(ArangoDBEngine.StorageEngineName.rocksdb));

StreamTransactionEntity tx1 = db.beginStreamTransaction(null);
StreamTransactionEntity tx2 = db.beginStreamTransaction(null);

List<String> createdIds = Arrays.asList(tx1.getId(), tx2.getId());
Set<TransactionEntity> gotTxs = db.getStreamTransactions().stream().
filter(it -> createdIds.contains(it.getId())).collect(Collectors.toSet());

assertThat(gotTxs.size(), is(createdIds.size()));
assertThat(gotTxs.stream()
.allMatch(it -> it.getStatus() == StreamTransactionStatus.running), is(true));

db.abortStreamTransaction(tx1.getId());
db.abortStreamTransaction(tx2.getId());
}

}