Fix initialization order of test primary, standby, and proxy
@@ -63,8 +63,6 @@ public abstract class DataStoreTestBase extends TestBase {
static final long GB = 1024 * 1024 * 1024;
- private NetworkErrorProxy proxy;
-
@Rule
public TemporaryPort serverPort = new TemporaryPort();
@@ -129,12 +127,10 @@ public abstract class DataStoreTestBase extends TestBase {
@Before
public void before() {
logger.info("Test begin: {}", testName.getMethodName());
- proxy = new NetworkErrorProxy(proxyPort.getPort(), getServerHost(), serverPort.getPort());
}
@After
public void after() {
- proxy.close();
logger.info("Test end: {}", testName.getMethodName());
}
@@ -342,19 +338,15 @@ public abstract class DataStoreTestBase extends TestBase {
NodeStore store = SegmentNodeStoreBuilders.builder(primary).build();
byte[] data = addTestContent(store, "server", blobSize);
- try (
- StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), primary, 1 * MB);
- StandbyClientSync clientSync = newStandbyClientSync(secondary, proxyPort.getPort())
- ) {
+ try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), primary, MB)) {
+ serverSync.start();
+ try (NetworkErrorProxy proxy = new NetworkErrorProxy(proxyPort.getPort(), getServerHost(), serverPort.getPort())) {
proxy.skipBytes(skipPosition, skipBytes);
proxy.flipByte(flipPosition);
proxy.connect();
-
- serverSync.start();
+ try (StandbyClientSync clientSync = newStandbyClientSync(secondary, proxyPort.getPort())) {
primary.flush();
-
clientSync.run();
-
if (skipBytes > 0 || flipPosition >= 0) {
if (!storesShouldBeEqual()) {
assertFalse("stores are not expected to be equal", primary.getHead().equals(secondary.getHead()));
@@ -369,6 +361,8 @@ public abstract class DataStoreTestBase extends TestBase {
}
assertEquals(primary.getHead(), secondary.getHead());
}
+ }
+ }
assertTrue(primary.getStats().getApproximateSize() < MB);
assertTrue(secondary.getStats().getApproximateSize() < MB);
