|
@@ -27,6 +27,7 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.LineNumberReader;
|
|
|
import java.io.StringReader;
|
|
|
+import java.util.concurrent.TimeoutException;
|
|
|
import java.util.regex.Pattern;
|
|
|
import org.apache.log4j.Layout;
|
|
|
import org.apache.log4j.Level;
|
|
@@ -57,7 +58,6 @@ public class ReadOnlyModeTest extends ZKTestCase {
|
|
|
@BeforeEach
|
|
|
public void setUp() throws Exception {
|
|
|
System.setProperty("readonlymode.enabled", "true");
|
|
|
- qu.startQuorum();
|
|
|
}
|
|
|
|
|
|
@AfterEach
|
|
@@ -72,6 +72,9 @@ public class ReadOnlyModeTest extends ZKTestCase {
|
|
|
@Test
|
|
|
@Timeout(value = 90)
|
|
|
public void testMultiTransaction() throws Exception {
|
|
|
+ qu.enableLocalSession(true);
|
|
|
+ qu.startQuorum();
|
|
|
+
|
|
|
CountdownWatcher watcher = new CountdownWatcher();
|
|
|
ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, watcher, true);
|
|
|
watcher.waitForConnected(CONNECTION_TIMEOUT); // ensure zk got connected
|
|
@@ -80,9 +83,12 @@ public class ReadOnlyModeTest extends ZKTestCase {
|
|
|
final String node1 = "/tnode1";
|
|
|
final String node2 = "/tnode2";
|
|
|
zk.create(node1, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
|
|
|
+ zk.close();
|
|
|
+ watcher.waitForDisconnected(CONNECTION_TIMEOUT);
|
|
|
|
|
|
watcher.reset();
|
|
|
qu.shutdown(2);
|
|
|
+ zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, watcher, true);
|
|
|
watcher.waitForConnected(CONNECTION_TIMEOUT);
|
|
|
assertEquals(States.CONNECTEDREADONLY, zk.getState(), "Should be in r-o mode");
|
|
|
|
|
@@ -110,6 +116,9 @@ public class ReadOnlyModeTest extends ZKTestCase {
|
|
|
@Test
|
|
|
@Timeout(value = 90)
|
|
|
public void testReadOnlyClient() throws Exception {
|
|
|
+ qu.enableLocalSession(true);
|
|
|
+ qu.startQuorum();
|
|
|
+
|
|
|
CountdownWatcher watcher = new CountdownWatcher();
|
|
|
ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, watcher, true);
|
|
|
watcher.waitForConnected(CONNECTION_TIMEOUT); // ensure zk got connected
|
|
@@ -161,6 +170,9 @@ public class ReadOnlyModeTest extends ZKTestCase {
|
|
|
@Test
|
|
|
@Timeout(value = 90)
|
|
|
public void testConnectionEvents() throws Exception {
|
|
|
+ qu.enableLocalSession(true);
|
|
|
+ qu.startQuorum();
|
|
|
+
|
|
|
CountdownWatcher watcher = new CountdownWatcher();
|
|
|
ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, watcher, true);
|
|
|
boolean success = false;
|
|
@@ -202,6 +214,9 @@ public class ReadOnlyModeTest extends ZKTestCase {
|
|
|
@Test
|
|
|
@Timeout(value = 90)
|
|
|
public void testSessionEstablishment() throws Exception {
|
|
|
+ qu.enableLocalSession(true);
|
|
|
+ qu.startQuorum();
|
|
|
+
|
|
|
qu.shutdown(2);
|
|
|
|
|
|
CountdownWatcher watcher = new CountdownWatcher();
|
|
@@ -230,6 +245,43 @@ public class ReadOnlyModeTest extends ZKTestCase {
|
|
|
zk.close();
|
|
|
}
|
|
|
|
|
|
+ @Test(timeout = 90000)
|
|
|
+ public void testGlobalSessionInRO() throws Exception {
|
|
|
+ qu.startQuorum();
|
|
|
+
|
|
|
+ CountdownWatcher watcher = new CountdownWatcher();
|
|
|
+ ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, watcher, true);
|
|
|
+ watcher.waitForConnected(CONNECTION_TIMEOUT);
|
|
|
+ LOG.info("global session created 0x{}", Long.toHexString(zk.getSessionId()));
|
|
|
+
|
|
|
+ watcher.reset();
|
|
|
+ qu.shutdown(2);
|
|
|
+ try {
|
|
|
+ watcher.waitForConnected(CONNECTION_TIMEOUT);
|
|
|
+ fail("Should not be able to renew a global session");
|
|
|
+ } catch (TimeoutException e) {
|
|
|
+ }
|
|
|
+ zk.close();
|
|
|
+
|
|
|
+ watcher.reset();
|
|
|
+ zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, watcher, true);
|
|
|
+ try {
|
|
|
+ watcher.waitForConnected(CONNECTION_TIMEOUT);
|
|
|
+ fail("Should not be able to create a global session");
|
|
|
+ } catch (TimeoutException e) {
|
|
|
+ }
|
|
|
+ zk.close();
|
|
|
+
|
|
|
+ qu.getPeer(1).peer.enableLocalSessions(true);
|
|
|
+ zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, watcher, true);
|
|
|
+ try {
|
|
|
+ watcher.waitForConnected(CONNECTION_TIMEOUT);
|
|
|
+ } catch (TimeoutException e) {
|
|
|
+ fail("Should be able to create a local session");
|
|
|
+ }
|
|
|
+ zk.close();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Ensures that client seeks for r/w servers while it's connected to r/o
|
|
|
* server.
|
|
@@ -238,6 +290,9 @@ public class ReadOnlyModeTest extends ZKTestCase {
|
|
|
@Test
|
|
|
@Timeout(value = 90)
|
|
|
public void testSeekForRwServer() throws Exception {
|
|
|
+ qu.enableLocalSession(true);
|
|
|
+ qu.startQuorum();
|
|
|
+
|
|
|
// setup the logger to capture all logs
|
|
|
Layout layout = Logger.getRootLogger().getAppender("CONSOLE").getLayout();
|
|
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|