mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 05:09:53 +01:00
Allow event executor tasks to be attached to transactions.
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.event.EventExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An action that's taken when a {@link Transaction} is committed.
|
||||||
|
*/
|
||||||
|
public interface CommitAction {
|
||||||
|
|
||||||
|
void accept(Visitor visitor);
|
||||||
|
|
||||||
|
interface Visitor {
|
||||||
|
|
||||||
|
@EventExecutor
|
||||||
|
void visit(EventAction a);
|
||||||
|
|
||||||
|
@EventExecutor
|
||||||
|
void visit(TaskAction a);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link CommitAction} that broadcasts an event.
|
||||||
|
*/
|
||||||
|
public class EventAction implements CommitAction {
|
||||||
|
|
||||||
|
private final Event event;
|
||||||
|
|
||||||
|
EventAction(Event event) {
|
||||||
|
this.event = event;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Event getEvent() {
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(Visitor visitor) {
|
||||||
|
visitor.visit(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.event.EventExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link CommitAction} that submits a task to the {@link EventExecutor}.
|
||||||
|
*/
|
||||||
|
public class TaskAction implements CommitAction {
|
||||||
|
|
||||||
|
private final Runnable task;
|
||||||
|
|
||||||
|
TaskAction(Runnable task) {
|
||||||
|
this.task = task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Runnable getTask() {
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(Visitor visitor) {
|
||||||
|
visitor.visit(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
package org.briarproject.bramble.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.event.EventExecutor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper around a database transaction. Transactions are not thread-safe.
|
* A wrapper around a database transaction. Transactions are not thread-safe.
|
||||||
*/
|
*/
|
||||||
@@ -17,7 +19,7 @@ public class Transaction {
|
|||||||
private final Object txn;
|
private final Object txn;
|
||||||
private final boolean readOnly;
|
private final boolean readOnly;
|
||||||
|
|
||||||
private List<Event> events = null;
|
private List<CommitAction> actions = null;
|
||||||
private boolean committed = false;
|
private boolean committed = false;
|
||||||
|
|
||||||
public Transaction(Object txn, boolean readOnly) {
|
public Transaction(Object txn, boolean readOnly) {
|
||||||
@@ -42,19 +44,27 @@ public class Transaction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Attaches an event to be broadcast when the transaction has been
|
* Attaches an event to be broadcast when the transaction has been
|
||||||
* committed.
|
* committed. The event will be broadcast on the {@link EventExecutor}.
|
||||||
*/
|
*/
|
||||||
public void attach(Event e) {
|
public void attach(Event e) {
|
||||||
if (events == null) events = new ArrayList<>();
|
if (actions == null) actions = new ArrayList<>();
|
||||||
events.add(e);
|
actions.add(new EventAction(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns any events attached to the transaction.
|
* Attaches a task to be executed when the transaction has been
|
||||||
|
* committed. The task will be run on the {@link EventExecutor}.
|
||||||
*/
|
*/
|
||||||
public List<Event> getEvents() {
|
public void attach(Runnable r) {
|
||||||
if (events == null) return Collections.emptyList();
|
if (actions == null) actions = new ArrayList<>();
|
||||||
return events;
|
actions.add(new TaskAction(r));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns any actions attached to the transaction.
|
||||||
|
*/
|
||||||
|
public List<CommitAction> getActions() {
|
||||||
|
return actions == null ? emptyList() : actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ import static java.lang.annotation.ElementType.PARAMETER;
|
|||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotation for injecting the executor for broadcasting events. Also used for
|
* Annotation for injecting the executor for broadcasting events and running
|
||||||
* annotating methods that should run on the event executor.
|
* tasks that need to run in a defined order with respect to events. Also used
|
||||||
|
* for annotating methods that should run on the event executor.
|
||||||
* <p>
|
* <p>
|
||||||
* The contract of this executor is that tasks are run in the order they're
|
* The contract of this executor is that tasks are run in the order they're
|
||||||
* submitted, tasks are not run concurrently, and submitting a task will never
|
* submitted, tasks are not run concurrently, and submitting a task will never
|
||||||
|
|||||||
@@ -7,11 +7,14 @@ import org.briarproject.bramble.api.contact.event.ContactRemovedEvent;
|
|||||||
import org.briarproject.bramble.api.contact.event.ContactStatusChangedEvent;
|
import org.briarproject.bramble.api.contact.event.ContactStatusChangedEvent;
|
||||||
import org.briarproject.bramble.api.contact.event.ContactVerifiedEvent;
|
import org.briarproject.bramble.api.contact.event.ContactVerifiedEvent;
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
|
import org.briarproject.bramble.api.db.CommitAction;
|
||||||
|
import org.briarproject.bramble.api.db.CommitAction.Visitor;
|
||||||
import org.briarproject.bramble.api.db.ContactExistsException;
|
import org.briarproject.bramble.api.db.ContactExistsException;
|
||||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
import org.briarproject.bramble.api.db.DbCallable;
|
import org.briarproject.bramble.api.db.DbCallable;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.DbRunnable;
|
import org.briarproject.bramble.api.db.DbRunnable;
|
||||||
|
import org.briarproject.bramble.api.db.EventAction;
|
||||||
import org.briarproject.bramble.api.db.Metadata;
|
import org.briarproject.bramble.api.db.Metadata;
|
||||||
import org.briarproject.bramble.api.db.MigrationListener;
|
import org.briarproject.bramble.api.db.MigrationListener;
|
||||||
import org.briarproject.bramble.api.db.NoSuchContactException;
|
import org.briarproject.bramble.api.db.NoSuchContactException;
|
||||||
@@ -20,9 +23,10 @@ import org.briarproject.bramble.api.db.NoSuchLocalAuthorException;
|
|||||||
import org.briarproject.bramble.api.db.NoSuchMessageException;
|
import org.briarproject.bramble.api.db.NoSuchMessageException;
|
||||||
import org.briarproject.bramble.api.db.NoSuchTransportException;
|
import org.briarproject.bramble.api.db.NoSuchTransportException;
|
||||||
import org.briarproject.bramble.api.db.NullableDbCallable;
|
import org.briarproject.bramble.api.db.NullableDbCallable;
|
||||||
|
import org.briarproject.bramble.api.db.TaskAction;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.bramble.api.event.Event;
|
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
import org.briarproject.bramble.api.event.EventExecutor;
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.identity.AuthorId;
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
@@ -64,6 +68,7 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -92,25 +97,29 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
private final Database<T> db;
|
private final Database<T> db;
|
||||||
private final Class<T> txnClass;
|
private final Class<T> txnClass;
|
||||||
private final EventBus eventBus;
|
private final EventBus eventBus;
|
||||||
private final ShutdownManager shutdown;
|
private final Executor eventExecutor;
|
||||||
|
private final ShutdownManager shutdownManager;
|
||||||
private final AtomicBoolean closed = new AtomicBoolean(false);
|
private final AtomicBoolean closed = new AtomicBoolean(false);
|
||||||
private final ReentrantReadWriteLock lock =
|
private final ReentrantReadWriteLock lock =
|
||||||
new ReentrantReadWriteLock(true);
|
new ReentrantReadWriteLock(true);
|
||||||
|
private final Visitor visitor = new CommitActionVisitor();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
DatabaseComponentImpl(Database<T> db, Class<T> txnClass, EventBus eventBus,
|
DatabaseComponentImpl(Database<T> db, Class<T> txnClass, EventBus eventBus,
|
||||||
ShutdownManager shutdown) {
|
@EventExecutor Executor eventExecutor,
|
||||||
|
ShutdownManager shutdownManager) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.txnClass = txnClass;
|
this.txnClass = txnClass;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.shutdown = shutdown;
|
this.eventExecutor = eventExecutor;
|
||||||
|
this.shutdownManager = shutdownManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean open(SecretKey key, @Nullable MigrationListener listener)
|
public boolean open(SecretKey key, @Nullable MigrationListener listener)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
boolean reopened = db.open(key, listener);
|
boolean reopened = db.open(key, listener);
|
||||||
shutdown.addShutdownHook(() -> {
|
shutdownManager.addShutdownHook(() -> {
|
||||||
try {
|
try {
|
||||||
close();
|
close();
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
@@ -161,7 +170,8 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
try {
|
try {
|
||||||
T txn = txnClass.cast(transaction.unbox());
|
T txn = txnClass.cast(transaction.unbox());
|
||||||
if (transaction.isCommitted()) {
|
if (transaction.isCommitted()) {
|
||||||
for (Event e : transaction.getEvents()) eventBus.broadcast(e);
|
for (CommitAction a : transaction.getActions())
|
||||||
|
a.accept(visitor);
|
||||||
} else {
|
} else {
|
||||||
db.abortTransaction(txn);
|
db.abortTransaction(txn);
|
||||||
}
|
}
|
||||||
@@ -976,4 +986,17 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
db.updateTransportKeys(txn, ks);
|
db.updateTransportKeys(txn, ks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class CommitActionVisitor implements Visitor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(EventAction a) {
|
||||||
|
eventBus.broadcast(a.getEvent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(TaskAction a) {
|
||||||
|
eventExecutor.execute(a.getTask());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package org.briarproject.bramble.db;
|
|||||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
import org.briarproject.bramble.api.event.EventExecutor;
|
||||||
import org.briarproject.bramble.api.lifecycle.ShutdownManager;
|
import org.briarproject.bramble.api.lifecycle.ShutdownManager;
|
||||||
import org.briarproject.bramble.api.sync.MessageFactory;
|
import org.briarproject.bramble.api.sync.MessageFactory;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
@@ -27,8 +29,9 @@ public class DatabaseModule {
|
|||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
DatabaseComponent provideDatabaseComponent(Database<Connection> db,
|
DatabaseComponent provideDatabaseComponent(Database<Connection> db,
|
||||||
EventBus eventBus, ShutdownManager shutdown) {
|
EventBus eventBus, @EventExecutor Executor eventExecutor,
|
||||||
|
ShutdownManager shutdownManager) {
|
||||||
return new DatabaseComponentImpl<>(db, Connection.class, eventBus,
|
return new DatabaseComponentImpl<>(db, Connection.class, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
@@ -87,9 +88,10 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private final Database<Object> database = context.mock(Database.class);
|
private final Database<Object> database = context.mock(Database.class);
|
||||||
private final ShutdownManager shutdown =
|
private final ShutdownManager shutdownManager =
|
||||||
context.mock(ShutdownManager.class);
|
context.mock(ShutdownManager.class);
|
||||||
private final EventBus eventBus = context.mock(EventBus.class);
|
private final EventBus eventBus = context.mock(EventBus.class);
|
||||||
|
private final Executor eventExecutor = context.mock(Executor.class);
|
||||||
|
|
||||||
private final SecretKey key = getSecretKey();
|
private final SecretKey key = getSecretKey();
|
||||||
private final Object txn = new Object();
|
private final Object txn = new Object();
|
||||||
@@ -132,9 +134,10 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private DatabaseComponent createDatabaseComponent(Database<Object> database,
|
private DatabaseComponent createDatabaseComponent(Database<Object> database,
|
||||||
EventBus eventBus, ShutdownManager shutdown) {
|
EventBus eventBus, Executor eventExecutor,
|
||||||
|
ShutdownManager shutdownManager) {
|
||||||
return new DatabaseComponentImpl<>(database, Object.class, eventBus,
|
return new DatabaseComponentImpl<>(database, Object.class, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -144,7 +147,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
// open()
|
// open()
|
||||||
oneOf(database).open(key, null);
|
oneOf(database).open(key, null);
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
oneOf(shutdown).addShutdownHook(with(any(Runnable.class)));
|
oneOf(shutdownManager).addShutdownHook(with(any(Runnable.class)));
|
||||||
will(returnValue(shutdownHandle));
|
will(returnValue(shutdownHandle));
|
||||||
// startTransaction()
|
// startTransaction()
|
||||||
oneOf(database).startTransaction();
|
oneOf(database).startTransaction();
|
||||||
@@ -207,7 +210,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(database).close();
|
oneOf(database).close();
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
assertFalse(db.open(key, null));
|
assertFalse(db.open(key, null));
|
||||||
db.transaction(false, transaction -> {
|
db.transaction(false, transaction -> {
|
||||||
@@ -238,7 +241,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(database).abortTransaction(txn);
|
oneOf(database).abortTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
db.addLocalMessage(transaction, message, metadata, true));
|
db.addLocalMessage(transaction, message, metadata, true));
|
||||||
@@ -263,7 +266,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(eventBus).broadcast(with(any(MessageSharedEvent.class)));
|
oneOf(eventBus).broadcast(with(any(MessageSharedEvent.class)));
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
db.addLocalMessage(transaction, message, metadata, true));
|
db.addLocalMessage(transaction, message, metadata, true));
|
||||||
@@ -281,7 +284,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
exactly(17).of(database).abortTransaction(txn);
|
exactly(17).of(database).abortTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
@@ -438,7 +441,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
exactly(3).of(database).abortTransaction(txn);
|
exactly(3).of(database).abortTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
@@ -481,7 +484,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
@@ -565,7 +568,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
@@ -668,7 +671,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
exactly(5).of(database).abortTransaction(txn);
|
exactly(5).of(database).abortTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
@@ -727,7 +730,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction -> {
|
db.transaction(false, transaction -> {
|
||||||
Ack a = db.generateAck(transaction, contactId, 123);
|
Ack a = db.generateAck(transaction, contactId, 123);
|
||||||
@@ -761,7 +764,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(eventBus).broadcast(with(any(MessagesSentEvent.class)));
|
oneOf(eventBus).broadcast(with(any(MessagesSentEvent.class)));
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
assertEquals(messages, db.generateBatch(transaction, contactId,
|
assertEquals(messages, db.generateBatch(transaction, contactId,
|
||||||
@@ -786,7 +789,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction -> {
|
db.transaction(false, transaction -> {
|
||||||
Offer o = db.generateOffer(transaction, contactId, 123, maxLatency);
|
Offer o = db.generateOffer(transaction, contactId, 123, maxLatency);
|
||||||
@@ -810,7 +813,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction -> {
|
db.transaction(false, transaction -> {
|
||||||
Request r = db.generateRequest(transaction, contactId, 123);
|
Request r = db.generateRequest(transaction, contactId, 123);
|
||||||
@@ -844,7 +847,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(eventBus).broadcast(with(any(MessagesSentEvent.class)));
|
oneOf(eventBus).broadcast(with(any(MessagesSentEvent.class)));
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
assertEquals(messages, db.generateRequestedBatch(transaction,
|
assertEquals(messages, db.generateRequestedBatch(transaction,
|
||||||
@@ -865,7 +868,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(eventBus).broadcast(with(any(MessagesAckedEvent.class)));
|
oneOf(eventBus).broadcast(with(any(MessagesAckedEvent.class)));
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction -> {
|
db.transaction(false, transaction -> {
|
||||||
Ack a = new Ack(singletonList(messageId));
|
Ack a = new Ack(singletonList(messageId));
|
||||||
@@ -903,7 +906,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(eventBus).broadcast(with(any(MessageToAckEvent.class)));
|
oneOf(eventBus).broadcast(with(any(MessageToAckEvent.class)));
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction -> {
|
db.transaction(false, transaction -> {
|
||||||
// Receive the message twice
|
// Receive the message twice
|
||||||
@@ -931,7 +934,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(eventBus).broadcast(with(any(MessageToAckEvent.class)));
|
oneOf(eventBus).broadcast(with(any(MessageToAckEvent.class)));
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
db.receiveMessage(transaction, contactId, message));
|
db.receiveMessage(transaction, contactId, message));
|
||||||
@@ -949,7 +952,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
db.receiveMessage(transaction, contactId, message));
|
db.receiveMessage(transaction, contactId, message));
|
||||||
@@ -989,7 +992,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(eventBus).broadcast(with(any(MessageToRequestEvent.class)));
|
oneOf(eventBus).broadcast(with(any(MessageToRequestEvent.class)));
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
Offer o = new Offer(asList(messageId, messageId1,
|
Offer o = new Offer(asList(messageId, messageId1,
|
||||||
messageId2, messageId3));
|
messageId2, messageId3));
|
||||||
@@ -1012,7 +1015,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(eventBus).broadcast(with(any(MessageRequestedEvent.class)));
|
oneOf(eventBus).broadcast(with(any(MessageRequestedEvent.class)));
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
Request r = new Request(singletonList(messageId));
|
Request r = new Request(singletonList(messageId));
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
@@ -1042,7 +1045,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
GroupVisibilityUpdatedEvent.class, 0));
|
GroupVisibilityUpdatedEvent.class, 0));
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
db.setGroupVisibility(transaction, contactId, groupId,
|
db.setGroupVisibility(transaction, contactId, groupId,
|
||||||
@@ -1076,7 +1079,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
GroupVisibilityUpdatedEvent.class, 0));
|
GroupVisibilityUpdatedEvent.class, 0));
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
db.setGroupVisibility(transaction, contactId, groupId,
|
db.setGroupVisibility(transaction, contactId, groupId,
|
||||||
@@ -1102,7 +1105,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
db.setGroupVisibility(transaction, contactId, groupId,
|
db.setGroupVisibility(transaction, contactId, groupId,
|
||||||
@@ -1132,7 +1135,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction -> {
|
db.transaction(false, transaction -> {
|
||||||
db.updateTransportKeys(transaction, keys);
|
db.updateTransportKeys(transaction, keys);
|
||||||
@@ -1171,7 +1174,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(true, transaction -> {
|
db.transaction(true, transaction -> {
|
||||||
// With visible group - return stored status
|
// With visible group - return stored status
|
||||||
@@ -1221,7 +1224,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(true, transaction -> {
|
db.transaction(true, transaction -> {
|
||||||
// With visible group - return stored status
|
// With visible group - return stored status
|
||||||
@@ -1287,7 +1290,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
db.transaction(false, transaction -> {
|
db.transaction(false, transaction -> {
|
||||||
// First merge should broadcast an event
|
// First merge should broadcast an event
|
||||||
@@ -1330,7 +1333,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
assertNotNull(db.startTransaction(firstTxnReadOnly));
|
assertNotNull(db.startTransaction(firstTxnReadOnly));
|
||||||
db.startTransaction(secondTxnReadOnly);
|
db.startTransaction(secondTxnReadOnly);
|
||||||
@@ -1351,7 +1354,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
@@ -1380,7 +1383,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
@@ -1401,7 +1404,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
// open()
|
// open()
|
||||||
oneOf(database).open(key, null);
|
oneOf(database).open(key, null);
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
oneOf(shutdown).addShutdownHook(with(any(Runnable.class)));
|
oneOf(shutdownManager).addShutdownHook(with(any(Runnable.class)));
|
||||||
will(returnValue(shutdownHandle));
|
will(returnValue(shutdownHandle));
|
||||||
// startTransaction()
|
// startTransaction()
|
||||||
oneOf(database).startTransaction();
|
oneOf(database).startTransaction();
|
||||||
@@ -1441,7 +1444,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(database).close();
|
oneOf(database).close();
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
assertFalse(db.open(key, null));
|
assertFalse(db.open(key, null));
|
||||||
db.transaction(false, transaction -> {
|
db.transaction(false, transaction -> {
|
||||||
|
|||||||
@@ -9,9 +9,12 @@ import org.briarproject.bramble.api.data.BdfDictionary;
|
|||||||
import org.briarproject.bramble.api.data.BdfEntry;
|
import org.briarproject.bramble.api.data.BdfEntry;
|
||||||
import org.briarproject.bramble.api.data.BdfList;
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
import org.briarproject.bramble.api.data.MetadataParser;
|
import org.briarproject.bramble.api.data.MetadataParser;
|
||||||
|
import org.briarproject.bramble.api.db.CommitAction;
|
||||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.db.EventAction;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.identity.AuthorInfo;
|
import org.briarproject.bramble.api.identity.AuthorInfo;
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
@@ -188,10 +191,12 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
blogManager.incomingMessage(txn, message, body, meta);
|
blogManager.incomingMessage(txn, message, body, meta);
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
|
|
||||||
assertEquals(1, txn.getEvents().size());
|
assertEquals(1, txn.getActions().size());
|
||||||
assertTrue(txn.getEvents().get(0) instanceof BlogPostAddedEvent);
|
CommitAction action = txn.getActions().get(0);
|
||||||
|
assertTrue(action instanceof EventAction);
|
||||||
BlogPostAddedEvent e = (BlogPostAddedEvent) txn.getEvents().get(0);
|
Event event = ((EventAction) action).getEvent();
|
||||||
|
assertTrue(event instanceof BlogPostAddedEvent);
|
||||||
|
BlogPostAddedEvent e = (BlogPostAddedEvent) event;
|
||||||
assertEquals(blog1.getId(), e.getGroupId());
|
assertEquals(blog1.getId(), e.getGroupId());
|
||||||
|
|
||||||
BlogPostHeader h = e.getHeader();
|
BlogPostHeader h = e.getHeader();
|
||||||
@@ -227,10 +232,12 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
blogManager.incomingMessage(txn, rssMessage, body, meta);
|
blogManager.incomingMessage(txn, rssMessage, body, meta);
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
|
|
||||||
assertEquals(1, txn.getEvents().size());
|
assertEquals(1, txn.getActions().size());
|
||||||
assertTrue(txn.getEvents().get(0) instanceof BlogPostAddedEvent);
|
CommitAction action = txn.getActions().get(0);
|
||||||
|
assertTrue(action instanceof EventAction);
|
||||||
BlogPostAddedEvent e = (BlogPostAddedEvent) txn.getEvents().get(0);
|
Event event = ((EventAction) action).getEvent();
|
||||||
|
assertTrue(event instanceof BlogPostAddedEvent);
|
||||||
|
BlogPostAddedEvent e = (BlogPostAddedEvent) event;
|
||||||
assertEquals(rssBlog.getId(), e.getGroupId());
|
assertEquals(rssBlog.getId(), e.getGroupId());
|
||||||
|
|
||||||
BlogPostHeader h = e.getHeader();
|
BlogPostHeader h = e.getHeader();
|
||||||
@@ -296,10 +303,12 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
blogManager.addLocalPost(post);
|
blogManager.addLocalPost(post);
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
|
|
||||||
assertEquals(1, txn.getEvents().size());
|
assertEquals(1, txn.getActions().size());
|
||||||
assertTrue(txn.getEvents().get(0) instanceof BlogPostAddedEvent);
|
CommitAction action = txn.getActions().get(0);
|
||||||
|
assertTrue(action instanceof EventAction);
|
||||||
BlogPostAddedEvent e = (BlogPostAddedEvent) txn.getEvents().get(0);
|
Event event = ((EventAction) action).getEvent();
|
||||||
|
assertTrue(event instanceof BlogPostAddedEvent);
|
||||||
|
BlogPostAddedEvent e = (BlogPostAddedEvent) event;
|
||||||
assertEquals(blog1.getId(), e.getGroupId());
|
assertEquals(blog1.getId(), e.getGroupId());
|
||||||
|
|
||||||
BlogPostHeader h = e.getHeader();
|
BlogPostHeader h = e.getHeader();
|
||||||
@@ -344,10 +353,12 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
blogManager.addLocalPost(post);
|
blogManager.addLocalPost(post);
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
|
|
||||||
assertEquals(1, txn.getEvents().size());
|
assertEquals(1, txn.getActions().size());
|
||||||
assertTrue(txn.getEvents().get(0) instanceof BlogPostAddedEvent);
|
CommitAction action = txn.getActions().get(0);
|
||||||
|
assertTrue(action instanceof EventAction);
|
||||||
BlogPostAddedEvent e = (BlogPostAddedEvent) txn.getEvents().get(0);
|
Event event = ((EventAction) action).getEvent();
|
||||||
|
assertTrue(event instanceof BlogPostAddedEvent);
|
||||||
|
BlogPostAddedEvent e = (BlogPostAddedEvent) event;
|
||||||
assertEquals(rssBlog.getId(), e.getGroupId());
|
assertEquals(rssBlog.getId(), e.getGroupId());
|
||||||
|
|
||||||
BlogPostHeader h = e.getHeader();
|
BlogPostHeader h = e.getHeader();
|
||||||
@@ -421,10 +432,12 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
postHeader);
|
postHeader);
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
|
|
||||||
assertEquals(1, txn.getEvents().size());
|
assertEquals(1, txn.getActions().size());
|
||||||
assertTrue(txn.getEvents().get(0) instanceof BlogPostAddedEvent);
|
CommitAction action = txn.getActions().get(0);
|
||||||
|
assertTrue(action instanceof EventAction);
|
||||||
BlogPostAddedEvent e = (BlogPostAddedEvent) txn.getEvents().get(0);
|
Event event = ((EventAction) action).getEvent();
|
||||||
|
assertTrue(event instanceof BlogPostAddedEvent);
|
||||||
|
BlogPostAddedEvent e = (BlogPostAddedEvent) event;
|
||||||
assertEquals(blog1.getId(), e.getGroupId());
|
assertEquals(blog1.getId(), e.getGroupId());
|
||||||
|
|
||||||
BlogPostHeader h = e.getHeader();
|
BlogPostHeader h = e.getHeader();
|
||||||
@@ -530,10 +543,12 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
originalPostHeader);
|
originalPostHeader);
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
|
|
||||||
assertEquals(1, txn.getEvents().size());
|
assertEquals(1, txn.getActions().size());
|
||||||
assertTrue(txn.getEvents().get(0) instanceof BlogPostAddedEvent);
|
CommitAction action = txn.getActions().get(0);
|
||||||
|
assertTrue(action instanceof EventAction);
|
||||||
BlogPostAddedEvent e = (BlogPostAddedEvent) txn.getEvents().get(0);
|
Event event = ((EventAction) action).getEvent();
|
||||||
|
assertTrue(event instanceof BlogPostAddedEvent);
|
||||||
|
BlogPostAddedEvent e = (BlogPostAddedEvent) event;
|
||||||
assertEquals(blog2.getId(), e.getGroupId());
|
assertEquals(blog2.getId(), e.getGroupId());
|
||||||
|
|
||||||
BlogPostHeader h = e.getHeader();
|
BlogPostHeader h = e.getHeader();
|
||||||
@@ -637,10 +652,12 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
originalPostHeader);
|
originalPostHeader);
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
|
|
||||||
assertEquals(1, txn.getEvents().size());
|
assertEquals(1, txn.getActions().size());
|
||||||
assertTrue(txn.getEvents().get(0) instanceof BlogPostAddedEvent);
|
CommitAction action = txn.getActions().get(0);
|
||||||
|
assertTrue(action instanceof EventAction);
|
||||||
BlogPostAddedEvent e = (BlogPostAddedEvent) txn.getEvents().get(0);
|
Event event = ((EventAction) action).getEvent();
|
||||||
|
assertTrue(event instanceof BlogPostAddedEvent);
|
||||||
|
BlogPostAddedEvent e = (BlogPostAddedEvent) event;
|
||||||
assertEquals(blog1.getId(), e.getGroupId());
|
assertEquals(blog1.getId(), e.getGroupId());
|
||||||
|
|
||||||
BlogPostHeader h = e.getHeader();
|
BlogPostHeader h = e.getHeader();
|
||||||
@@ -787,10 +804,12 @@ public class BlogManagerImplTest extends BriarTestCase {
|
|||||||
originalCommentHeader);
|
originalCommentHeader);
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
|
|
||||||
assertEquals(1, txn.getEvents().size());
|
assertEquals(1, txn.getActions().size());
|
||||||
assertTrue(txn.getEvents().get(0) instanceof BlogPostAddedEvent);
|
CommitAction action = txn.getActions().get(0);
|
||||||
|
assertTrue(action instanceof EventAction);
|
||||||
BlogPostAddedEvent e = (BlogPostAddedEvent) txn.getEvents().get(0);
|
Event event = ((EventAction) action).getEvent();
|
||||||
|
assertTrue(event instanceof BlogPostAddedEvent);
|
||||||
|
BlogPostAddedEvent e = (BlogPostAddedEvent) event;
|
||||||
assertEquals(blog2.getId(), e.getGroupId());
|
assertEquals(blog2.getId(), e.getGroupId());
|
||||||
|
|
||||||
BlogPostHeader h = e.getHeader();
|
BlogPostHeader h = e.getHeader();
|
||||||
|
|||||||
Reference in New Issue
Block a user