Fix: better test of the NetworkVirtualPrinter
parent
c78b78aa3c
commit
4ddd5f852a
|
@ -37,6 +37,7 @@ public class NetworkVirtualPrinterTest {
|
||||||
private static final String SUB_ADDRESS = "";
|
private static final String SUB_ADDRESS = "";
|
||||||
private static final int PORT = 8080;
|
private static final int PORT = 8080;
|
||||||
|
|
||||||
|
private Semaphore semaphore0;
|
||||||
private Semaphore semaphore1;
|
private Semaphore semaphore1;
|
||||||
private Semaphore semaphore2;
|
private Semaphore semaphore2;
|
||||||
private Throwable thrown;
|
private Throwable thrown;
|
||||||
|
@ -45,6 +46,9 @@ public class NetworkVirtualPrinterTest {
|
||||||
private NetworkVirtualPrinter networkPrinter;
|
private NetworkVirtualPrinter networkPrinter;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private class ScanHandler implements FutureCallback<ScannedData> {
|
private class ScanHandler implements FutureCallback<ScannedData> {
|
||||||
|
|
||||||
private final ScannedData expectedData;
|
private final ScannedData expectedData;
|
||||||
|
@ -70,9 +74,11 @@ public class NetworkVirtualPrinterTest {
|
||||||
private class CommitHandler extends OutputDeviceCommitCallback {
|
private class CommitHandler extends OutputDeviceCommitCallback {
|
||||||
|
|
||||||
private boolean success;
|
private boolean success;
|
||||||
|
public String errorMessage;
|
||||||
|
|
||||||
public CommitHandler(int requestId, long serialNumber) {
|
public CommitHandler(int requestId, long serialNumber) {
|
||||||
super(requestId, serialNumber, null, null);
|
super(requestId, serialNumber, null, null);
|
||||||
|
errorMessage = null;
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,11 +86,13 @@ public class NetworkVirtualPrinterTest {
|
||||||
public void onSuccess(Void v) {
|
public void onSuccess(Void v) {
|
||||||
System.out.println("CommitHandler success");
|
System.out.println("CommitHandler success");
|
||||||
success = true;
|
success = true;
|
||||||
|
semaphore0.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable t) {
|
public void onFailure(Throwable t) {
|
||||||
assertThat("Commit to ballot failed " + t.getMessage(), false);
|
errorMessage = "Commit to ballot failed " + t.getMessage();
|
||||||
|
semaphore0.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean gotSuccess() {
|
public boolean gotSuccess() {
|
||||||
|
@ -95,9 +103,11 @@ public class NetworkVirtualPrinterTest {
|
||||||
private class CastHandler extends OutputDeviceFinalizeCallback {
|
private class CastHandler extends OutputDeviceFinalizeCallback {
|
||||||
|
|
||||||
private boolean success;
|
private boolean success;
|
||||||
|
public String errorMessage;
|
||||||
|
|
||||||
public CastHandler(int requestId, long serialNumber) {
|
public CastHandler(int requestId, long serialNumber) {
|
||||||
super(requestId, serialNumber, null, null);
|
super(requestId, serialNumber, null, null);
|
||||||
|
errorMessage = null;
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,8 +120,8 @@ public class NetworkVirtualPrinterTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable t) {
|
public void onFailure(Throwable t) {
|
||||||
|
errorMessage = "Cast to ballot failed " + t.getMessage();
|
||||||
semaphore1.release();
|
semaphore1.release();
|
||||||
assertThat("Cast ballot failed " + t.getMessage(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean gotSuccess() {
|
public boolean gotSuccess() {
|
||||||
|
@ -126,6 +136,7 @@ public class NetworkVirtualPrinterTest {
|
||||||
|
|
||||||
scanner = new PollingStationWebScanner(PORT, SUB_ADDRESS);
|
scanner = new PollingStationWebScanner(PORT, SUB_ADDRESS);
|
||||||
|
|
||||||
|
semaphore0 = new Semaphore(0);
|
||||||
semaphore1 = new Semaphore(0);
|
semaphore1 = new Semaphore(0);
|
||||||
semaphore2 = new Semaphore(0);
|
semaphore2 = new Semaphore(0);
|
||||||
thrown = null;
|
thrown = null;
|
||||||
|
@ -136,11 +147,11 @@ public class NetworkVirtualPrinterTest {
|
||||||
assertThat("Could not start server: " + e.getMessage(), false);
|
assertThat("Could not start server: " + e.getMessage(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
networkPrinter = new NetworkVirtualPrinter(ADDRESS + ":" + PORT);
|
networkPrinter = new NetworkVirtualPrinter(ADDRESS + ":" + PORT);
|
||||||
Thread outputThread = new Thread(networkPrinter);
|
Thread outputThread = new Thread(networkPrinter);
|
||||||
outputThread.setName("Meerkat VB-Output Thread");
|
outputThread.setName("Meerkat VB-Output Thread");
|
||||||
outputThread.start();
|
outputThread.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -191,12 +202,14 @@ public class NetworkVirtualPrinterTest {
|
||||||
|
|
||||||
CommitHandler commitHandler = new CommitHandler(0, serialNumber);
|
CommitHandler commitHandler = new CommitHandler(0, serialNumber);
|
||||||
networkPrinter.commitToBallot(plaintextBallot, signedEncryptedBallot, commitHandler);
|
networkPrinter.commitToBallot(plaintextBallot, signedEncryptedBallot, commitHandler);
|
||||||
|
|
||||||
|
semaphore0.acquire();
|
||||||
|
|
||||||
CastHandler castHandler = new CastHandler(1, serialNumber);
|
CastHandler castHandler = new CastHandler(1, serialNumber);
|
||||||
networkPrinter.castBallot(castHandler);
|
networkPrinter.castBallot(castHandler);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
semaphore1.acquire();
|
semaphore1.acquire();
|
||||||
|
|
||||||
semaphore2.acquire();
|
semaphore2.acquire();
|
||||||
|
|
||||||
// Make sure the response was valid
|
// Make sure the response was valid
|
||||||
|
|
Loading…
Reference in New Issue