From 9d525aa042c6fb4111e88d7913ede66aba6e24db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Wed, 25 Apr 2012 14:37:02 +0200 Subject: Make sure to report the *correct* failed master. --- same/src/main/java/com/orbekk/same/Client.java | 12 ++++++------ same/src/test/java/com/orbekk/same/FunctionalTest.java | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'same') 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 stateListeners = new ArrayList(); @@ -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 done) { @@ -305,9 +306,8 @@ public class Client { } } - public void startMasterElection() { + public void startMasterElection(MasterState failedMaster) { List participants = state.getList(State.PARTICIPANTS); - final MasterState failedMaster = masterInfo; RpcCallback done = new RpcCallback() { @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)); -- cgit v1.2.3