Skip to content

Commit

Permalink
Add internal server state machine tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuujo committed Aug 30, 2015
1 parent f3449c9 commit f865628
Show file tree
Hide file tree
Showing 15 changed files with 426 additions and 51 deletions.
Expand Up @@ -152,6 +152,15 @@ ServerSession registerCommand(long sequence, Runnable runnable) {
return this;
}

/**
* Returns the command sequence number.
*
* @return The command sequence number.
*/
long getSequence() {
return command;
}

/**
* Returns the next session sequence number.
*
Expand Down
Expand Up @@ -286,7 +286,7 @@ private CompletableFuture<Object> executeCommand(CommandEntry entry, ServerSessi
* @return The result.
*/
@SuppressWarnings("unchecked")
CompletableFuture<Object> apply(QueryEntry entry) {
private CompletableFuture<Object> apply(QueryEntry entry) {
ServerSession session = executor.context().sessions().getSession(entry.getSession());

// If the session is null then that indicates that the session already timed out or it never existed.
Expand Down Expand Up @@ -335,7 +335,7 @@ private CompletableFuture<Object> executeQuery(QueryEntry entry, CompletableFutu
* @param entry The entry to apply.
* @return The result.
*/
CompletableFuture<Long> apply(NoOpEntry entry) {
private CompletableFuture<Long> apply(NoOpEntry entry) {
// Iterate through all the server sessions and reset timestamps. This ensures that sessions do not
// timeout during leadership changes.
for (ServerSession session : executor.context().sessions().sessions.values()) {
Expand All @@ -359,24 +359,6 @@ private void expireSessions(long timestamp) {
}
}

/**
* Expires a session.
*/
private <T> CompletableFuture<T> expireSession(long sessionId, Context context) {
CompletableFuture<T> future = new CompletableFuture<>();
ServerSession session = executor.context().sessions().unregisterSession(sessionId);
if (session != null) {
executor.executor().execute(() -> {
session.expire();
stateMachine.expire(session);
context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("unknown session: " + sessionId)));
});
} else {
context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("unknown session: " + sessionId)));
}
return future;
}

@Override
public void close() {
executor.close();
Expand Down
Expand Up @@ -35,9 +35,9 @@ public class CommandEntry extends OperationEntry<CommandEntry> {
private long sequence;
private Command command;

/**
* @throws NullPointerException if {@code referenceManager} is null
*/
public CommandEntry() {
}

public CommandEntry(ReferenceManager<Entry<?>> referenceManager) {
super(referenceManager);
}
Expand Down
Expand Up @@ -35,9 +35,6 @@ public class ConfigurationEntry extends RaftEntry<ConfigurationEntry> {
public ConfigurationEntry() {
}

/**
* @throws NullPointerException if {@code referenceManager} is null
*/
public ConfigurationEntry(ReferenceManager<Entry<?>> referenceManager) {
super(referenceManager);
}
Expand Down
Expand Up @@ -32,9 +32,9 @@ public class KeepAliveEntry extends SessionEntry<KeepAliveEntry> {
private long commandSequence;
private long eventSequence;

/**
* @throws NullPointerException if {@code referenceManager} is null
*/
public KeepAliveEntry() {
}

public KeepAliveEntry(ReferenceManager<Entry<?>> referenceManager) {
super(referenceManager);
}
Expand Down
Expand Up @@ -27,9 +27,9 @@
@SerializeWith(id=300)
public class NoOpEntry extends TimestampedEntry<NoOpEntry> {

/**
* @throws NullPointerException if {@code referenceManager} is null
*/
public NoOpEntry() {
}

public NoOpEntry(ReferenceManager<Entry<?>> referenceManager) {
super(referenceManager);
}
Expand Down
Expand Up @@ -26,9 +26,9 @@
*/
public abstract class OperationEntry<T extends OperationEntry<T>> extends SessionEntry<T> {

/**
* @throws NullPointerException if {@code referenceManager} is null
*/
protected OperationEntry() {
}

protected OperationEntry(ReferenceManager<Entry<?>> referenceManager) {
super(referenceManager);
}
Expand Down
Expand Up @@ -35,6 +35,9 @@ public class QueryEntry extends OperationEntry<QueryEntry> {
private long version;
private Query query;

public QueryEntry() {
}

public QueryEntry(ReferenceManager<Entry<?>> referenceManager) {
super(referenceManager);
}
Expand Down
Expand Up @@ -18,9 +18,6 @@ protected RaftEntry() {
super();
}

/**
* @throws NullPointerException if {@code referenceManager} is null
*/
protected RaftEntry(ReferenceManager<Entry<?>> referenceManager) {
super(referenceManager);
}
Expand Down
Expand Up @@ -38,9 +38,6 @@ public class RegisterEntry extends TimestampedEntry<RegisterEntry> {
public RegisterEntry() {
}

/**
* @throws NullPointerException if {@code referenceManager} is null
*/
public RegisterEntry(ReferenceManager<Entry<?>> referenceManager) {
super(referenceManager);
}
Expand Down
Expand Up @@ -32,9 +32,6 @@ public abstract class SessionEntry<T extends SessionEntry<T>> extends Timestampe
protected SessionEntry() {
}

/**
* @throws NullPointerException if {@code referenceManager} is null
*/
protected SessionEntry(ReferenceManager<Entry<?>> referenceManager) {
super(referenceManager);
}
Expand Down
Expand Up @@ -32,9 +32,6 @@ public abstract class TimestampedEntry<T extends TimestampedEntry<T>> extends Ra
protected TimestampedEntry() {
}

/**
* @throws NullPointerException if {@code referenceManager} is null
*/
protected TimestampedEntry(ReferenceManager<Entry<?>> referenceManager) {
super(referenceManager);
}
Expand Down

0 comments on commit f865628

Please sign in to comment.