summaryrefslogtreecommitdiff
path: root/same/src
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-25 14:37:02 +0200
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-25 14:37:56 +0200
commit9d525aa042c6fb4111e88d7913ede66aba6e24db (patch)
tree0e6eed38f60ac9fe95774afb5e02cf3cd5c50599 /same/src
parent1cde431ec7e0f5f29ec329c1949c7f5c76366ce5 (diff)
Make sure to report the *correct* failed master.
Diffstat (limited to 'same/src')
-rw-r--r--same/src/main/java/com/orbekk/same/Client.java12
-rw-r--r--same/src/test/java/com/orbekk/same/FunctionalTest.java4
2 files changed, 8 insertions, 8 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java
index bef096b..19debdb 100644
--- a/same/src/main/java/com/orbekk/same/Client.java
+++ b/same/src/main/java/com/orbekk/same/Client.java
@@ -33,6 +33,7 @@ public class Client {
private volatile MasterState masterInfo;
private final RpcFactory rpcf;
private final ExecutorService executor;
+ private final ClientInterface clientInterface = new ClientInterfaceImpl();
private List<StateChangedListener> stateListeners =
new ArrayList<StateChangedListener>();
@@ -50,6 +51,8 @@ public class Client {
@Override
public DelayedOperation set(Component component) {
+ // Callbacks need to report the correct master.
+ final MasterState currentMasterInfo = masterInfo;
final DelayedOperation op = new DelayedOperation();
if (connectionState != ConnectionState.STABLE) {
op.complete(DelayedOperation.Status.createError(
@@ -62,7 +65,7 @@ public class Client {
if (master == null) {
op.complete(DelayedOperation.Status.createError(
"Not connected to master."));
- startMasterElection();
+ startMasterElection(currentMasterInfo);
return op;
}
final Rpc rpc = rpcf.create();
@@ -75,7 +78,7 @@ public class Client {
"request: {}", rpc.errorText());
op.complete(DelayedOperation.Status.createError(
"Error contacting master. Try again later."));
- startMasterElection();
+ startMasterElection(currentMasterInfo);
} else {
if (response.getSuccess()) {
op.complete(DelayedOperation.Status.createOk());
@@ -111,8 +114,6 @@ public class Client {
}
}
- private ClientInterface clientInterface = new ClientInterfaceImpl();
-
private Services.Client newServiceImpl = new Services.Client() {
@Override public void setState(RpcController controller,
Services.Component request, RpcCallback<Empty> done) {
@@ -305,9 +306,8 @@ public class Client {
}
}
- public void startMasterElection() {
+ public void startMasterElection(MasterState failedMaster) {
List<String> participants = state.getList(State.PARTICIPANTS);
- final MasterState failedMaster = masterInfo;
RpcCallback<Empty> done = new RpcCallback<Empty>() {
@Override public void run(Empty unused) {
diff --git a/same/src/test/java/com/orbekk/same/FunctionalTest.java b/same/src/test/java/com/orbekk/same/FunctionalTest.java
index 2a73656..7b50b5a 100644
--- a/same/src/test/java/com/orbekk/same/FunctionalTest.java
+++ b/same/src/test/java/com/orbekk/same/FunctionalTest.java
@@ -147,7 +147,7 @@ public class FunctionalTest {
client1.setMasterController(controller);
client2.setMasterController(controller);
client3.setMasterController(controller);
- client1.startMasterElection();
+ client1.startMasterElection(master.getMasterInfo());
awaitExecution();
newMaster.performWork();
assertThat(client1.getMaster().getMasterLocation(), is(newMasterLocation));
@@ -176,7 +176,7 @@ public class FunctionalTest {
client1.setMasterController(controller);
client2.setMasterController(controller);
client3.setMasterController(controller);
- client1.startMasterElection();
+ client1.startMasterElection(master.getMasterInfo());
awaitExecution();
newMaster.performWork();
assertThat(client1.getMaster().getMasterUrl(), is(newMasterUrl));