Skip to content

Commit

Permalink
Revert CommitResponse result to ByteBuffer instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuujo committed Jan 31, 2015
1 parent 100cbdd commit 5be90dd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
Expand Up @@ -14,6 +14,7 @@
*/
package net.kuujo.copycat.protocol.rpc;

import java.nio.ByteBuffer;
import java.util.Objects;

/**
Expand Down Expand Up @@ -42,14 +43,14 @@ public static Builder builder(CommitResponse response) {
return new Builder(response);
}

private byte[] result;
private ByteBuffer result;

/**
* Returns the commit result.
*
* @return The commit result.
*/
public byte[] result() {
public ByteBuffer result() {
return result;
}

Expand Down Expand Up @@ -93,7 +94,7 @@ private Builder(CommitResponse response) {
* @param result The response result.
* @return The response builder.
*/
public Builder withResult(byte[] result) {
public Builder withResult(ByteBuffer result) {
response.result = result;
return this;
}
Expand Down
Expand Up @@ -16,18 +16,17 @@
package net.kuujo.copycat.resource.internal;

import net.kuujo.copycat.cluster.internal.coordinator.CoordinatedResourceConfig;
import net.kuujo.copycat.cluster.internal.manager.ClusterManager;
import net.kuujo.copycat.cluster.internal.coordinator.DefaultClusterCoordinator;
import net.kuujo.copycat.util.internal.Assert;
import net.kuujo.copycat.util.concurrent.Futures;
import net.kuujo.copycat.cluster.internal.manager.ClusterManager;
import net.kuujo.copycat.log.LogManager;
import net.kuujo.copycat.protocol.rpc.CommitRequest;
import net.kuujo.copycat.protocol.Consistency;
import net.kuujo.copycat.protocol.rpc.CommitRequest;
import net.kuujo.copycat.protocol.rpc.QueryRequest;
import net.kuujo.copycat.protocol.rpc.Response;
import net.kuujo.copycat.util.concurrent.Futures;
import net.kuujo.copycat.util.internal.Assert;

import java.nio.ByteBuffer;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ScheduledFuture;
Expand Down Expand Up @@ -156,7 +155,7 @@ public synchronized CompletableFuture<ByteBuffer> commit(ByteBuffer entry) {
context.commit(request).whenComplete((response, error) -> {
if (error == null) {
if (response.status() == Response.Status.OK) {
future.complete(ByteBuffer.wrap(response.result()));
future.complete(response.result());
} else {
future.completeExceptionally(response.error());
}
Expand Down
Expand Up @@ -213,12 +213,9 @@ public CompletableFuture<CommitResponse> commit(final CommitRequest request) {
if (isOpen()) {
if (error == null) {
try {
ByteBuffer result = consumer.apply(index, entry);
byte[] bytes = new byte[result.remaining()];
result.get(bytes);
future.complete(logResponse(CommitResponse.builder()
.withUri(context.getLocalMember())
.withResult(bytes)
.withResult(consumer.apply(index, entry))
.build()));
} catch (Exception e) {
future.complete(logResponse(CommitResponse.builder()
Expand Down
Expand Up @@ -95,7 +95,7 @@ public void testCommitResponseBuilderFailsWithoutConfiguration() {
*/
@Test(expectedExceptions = NullPointerException.class)
public void testCommitResponseBuilderFailsWithoutMember() {
CommitResponse.builder().withResult("Hello world!".getBytes()).build();
CommitResponse.builder().withResult(ByteBuffer.wrap("Hello world!".getBytes())).build();
}

/**
Expand Down Expand Up @@ -124,10 +124,10 @@ public void testCommitResponseBuilderSucceedsWithNullResult() {
public void testCommitResponseBuilderSucceedsWithValidConfiguration() {
CommitResponse response = CommitResponse.builder()
.withUri("foo")
.withResult("Hello world!".getBytes())
.withResult(ByteBuffer.wrap("Hello world!".getBytes()))
.build();
assertEquals(response.uri(), "foo");
assertEquals(new String(response.result()), "Hello world!");
assertEquals(new String(response.result().array()), "Hello world!");
}

/**
Expand Down
Expand Up @@ -39,6 +39,7 @@ public void testPassiveEvents() throws Throwable {
EventLog<String> passive = cluster.passiveResources().iterator().next();
passive.consumer(message -> {
threadAssertEquals(message, "Hello world!");
resume();
});

EventLog<String> active = cluster.activeResources().iterator().next();
Expand Down

0 comments on commit 5be90dd

Please sign in to comment.