use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.
the class DataStoreTestBase method testSyncBigBlob.
/*
* See OAK-5902.
*/
@Test
public void testSyncBigBlob() throws Exception {
final long blobSize = GB;
final int seed = 13;
FileStore primary = getPrimary();
FileStore secondary = getSecondary();
NodeStore store = SegmentNodeStoreBuilders.builder(primary).build();
addTestContentOnTheFly(store, "server", blobSize, seed);
try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), primary, 8 * MB);
StandbyClientSync cl = new StandbyClientSync(getServerHost(), serverPort.getPort(), secondary, false, 2 * 60 * 1000, false, folder.newFolder())) {
serverSync.start();
primary.flush();
cl.run();
assertEquals(primary.getHead(), secondary.getHead());
}
assertTrue(primary.getStats().getApproximateSize() < MB);
assertTrue(secondary.getStats().getApproximateSize() < MB);
PropertyState ps = secondary.getHead().getChildNode("root").getChildNode("server").getProperty("testBlob");
assertNotNull(ps);
assertEquals(Type.BINARY.tag(), ps.getType().tag());
Blob b = ps.getValue(Type.BINARY);
assertEquals(blobSize, b.length());
try (InputStream randomInputStream = newRandomInputStream(blobSize, seed);
InputStream blobInputStream = b.getNewStream()) {
assertTrue(IOUtils.contentEquals(randomInputStream, blobInputStream));
}
}
use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.
the class DataStoreTestBase method testSyncUpdatedBinaryProperty.
/*
* See OAK-4969.
*/
@Test
public void testSyncUpdatedBinaryProperty() throws Exception {
final int blobSize = 5 * MB;
FileStore primary = getPrimary();
FileStore secondary = getSecondary();
NodeStore store = SegmentNodeStoreBuilders.builder(primary).build();
try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), primary, MB);
StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), serverPort.getPort(), secondary, false, getClientTimeout(), false, folder.newFolder())) {
serverSync.start();
addTestContent(store, "server", blobSize);
primary.flush();
clientSync.run();
assertEquals(primary.getHead(), secondary.getHead());
addTestContent(store, "server", blobSize);
primary.flush();
clientSync.run();
assertEquals(primary.getHead(), secondary.getHead());
}
}
use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.
the class FailoverMultipleClientsTestIT method testMultipleClients.
@Test
public void testMultipleClients() throws Exception {
FileStore storeS = serverFileStore.fileStore();
FileStore storeC = clientFileStore1.fileStore();
FileStore storeC2 = clientFileStore2.fileStore();
NodeStore store = SegmentNodeStoreBuilders.builder(storeS).build();
try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), storeS, MB);
StandbyClientSync cl1 = new StandbyClientSync(getServerHost(), serverPort.getPort(), storeC, false, getClientTimeout(), false, folder.newFolder());
StandbyClientSync cl2 = new StandbyClientSync(getServerHost(), serverPort.getPort(), storeC2, false, getClientTimeout(), false, folder.newFolder())) {
serverSync.start();
SegmentTestUtils.addTestContent(store, "server");
// this speeds up the test a little bit...
storeS.flush();
assertFalse("first client has invalid initial store!", storeS.getHead().equals(storeC.getHead()));
assertFalse("second client has invalid initial store!", storeS.getHead().equals(storeC2.getHead()));
assertEquals(storeC.getHead(), storeC2.getHead());
cl1.run();
cl2.run();
assertEquals(storeS.getHead(), storeC.getHead());
assertEquals(storeS.getHead(), storeC2.getHead());
cl1.stop();
SegmentTestUtils.addTestContent(store, "test");
storeS.flush();
cl1.run();
cl2.run();
assertEquals(storeS.getHead(), storeC2.getHead());
assertFalse("first client updated in stopped state!", storeS.getHead().equals(storeC.getHead()));
cl1.start();
cl1.run();
assertEquals(storeS.getHead(), storeC.getHead());
}
}
use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.
the class MBeanIT method testClientAndServerEmptyConfig.
@Test
public void testClientAndServerEmptyConfig() throws Exception {
System.setProperty(StandbyClientSync.CLIENT_ID_PROPERTY_NAME, "Bar");
MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
ObjectName clientStatus, serverStatus;
try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), serverFileStore.fileStore(), MB);
StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), serverPort.getPort(), clientFileStore.fileStore(), false, getClientTimeout(), false, folder.newFolder())) {
serverSync.start();
serverFileStore.fileStore().flush();
clientSync.start();
clientSync.run();
clientStatus = new ObjectName(clientSync.getMBeanName());
serverStatus = new ObjectName(serverSync.getMBeanName());
ObjectName status = new ObjectName(StandbyStatusMBean.JMX_NAME + ",id=*");
Set<ObjectName> instances = jmxServer.queryNames(status, null);
assertEquals(3, instances.size());
ObjectName connectionStatus = null;
for (ObjectName s : instances) {
if (!s.equals(clientStatus) && !s.equals(serverStatus)) {
connectionStatus = s;
}
}
assertNotNull(connectionStatus);
assertTrue(jmxServer.isRegistered(clientStatus));
assertTrue(jmxServer.isRegistered(serverStatus));
assertTrue(jmxServer.isRegistered(connectionStatus));
String m = jmxServer.getAttribute(clientStatus, "Mode").toString();
if (!m.startsWith("client: ")) {
fail("unexpected mode " + m);
}
assertEquals("primary", jmxServer.getAttribute(serverStatus, "Mode"));
assertEquals(true, jmxServer.getAttribute(serverStatus, "Running"));
assertEquals(true, jmxServer.getAttribute(clientStatus, "Running"));
assertEquals("0", jmxServer.getAttribute(clientStatus, "FailedRequests").toString());
assertEquals("0", jmxServer.getAttribute(clientStatus, "SecondsSinceLastSuccess").toString());
assertEquals("0", jmxServer.invoke(clientStatus, "calcFailedRequests", null, null).toString());
assertEquals("0", jmxServer.invoke(clientStatus, "calcSecondsSinceLastSuccess", null, null).toString());
Thread.sleep(1000);
assertEquals("0", jmxServer.getAttribute(clientStatus, "FailedRequests").toString());
assertEquals("1", jmxServer.getAttribute(clientStatus, "SecondsSinceLastSuccess").toString());
assertEquals("0", jmxServer.invoke(clientStatus, "calcFailedRequests", null, null).toString());
assertEquals("1", jmxServer.invoke(clientStatus, "calcSecondsSinceLastSuccess", null, null).toString());
assertEquals(1L, jmxServer.getAttribute(connectionStatus, "TransferredSegments"));
// stop the master
jmxServer.invoke(serverStatus, "stop", null, null);
assertEquals(false, jmxServer.getAttribute(serverStatus, "Running"));
m = jmxServer.getAttribute(serverStatus, "Status").toString();
if (!m.equals(StandbyStatusMBean.STATUS_STOPPED) && !m.equals("channel unregistered")) {
fail("unexpected Status" + m);
}
// restart the master
jmxServer.invoke(serverStatus, "start", null, null);
assertEquals(true, jmxServer.getAttribute(serverStatus, "Running"));
assertEquals(true, jmxServer.getAttribute(clientStatus, "Running"));
m = jmxServer.getAttribute(serverStatus, "Status").toString();
if (!m.equals(StandbyStatusMBean.STATUS_RUNNING) && !m.equals("channel unregistered")) {
fail("unexpected Status" + m);
}
// stop the slave
jmxServer.invoke(clientStatus, "stop", null, null);
assertEquals(true, jmxServer.getAttribute(serverStatus, "Running"));
assertEquals(false, jmxServer.getAttribute(clientStatus, "Running"));
assertEquals(StandbyStatusMBean.STATUS_STOPPED, jmxServer.getAttribute(clientStatus, "Status"));
// restart the slave
jmxServer.invoke(clientStatus, "start", null, null);
assertEquals(true, jmxServer.getAttribute(clientStatus, "Running"));
assertEquals(StandbyStatusMBean.STATUS_RUNNING, jmxServer.getAttribute(clientStatus, "Status"));
}
assertTrue(!jmxServer.isRegistered(clientStatus));
assertTrue(!jmxServer.isRegistered(serverStatus));
}
use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.
the class MBeanIT method testServerEmptyConfig.
@Test
public void testServerEmptyConfig() throws Exception {
MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
ObjectName status = new ObjectName(StandbyStatusMBean.JMX_NAME + ",id=*");
try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), serverFileStore.fileStore(), 1 * MB)) {
serverSync.start();
Set<ObjectName> instances = jmxServer.queryNames(status, null);
assertEquals(1, instances.size());
status = instances.toArray(new ObjectName[0])[0];
assertEquals(new ObjectName(serverSync.getMBeanName()), status);
assertTrue(jmxServer.isRegistered(status));
assertEquals("primary", jmxServer.getAttribute(status, "Mode"));
String m = jmxServer.getAttribute(status, "Status").toString();
if (!m.equals(StandbyStatusMBean.STATUS_RUNNING) && !m.equals("channel unregistered")) {
fail("unexpected Status " + m);
}
assertEquals(StandbyStatusMBean.STATUS_RUNNING, jmxServer.getAttribute(status, "Status"));
assertEquals(true, jmxServer.getAttribute(status, "Running"));
jmxServer.invoke(status, "stop", null, null);
assertEquals(false, jmxServer.getAttribute(status, "Running"));
assertEquals(StandbyStatusMBean.STATUS_STOPPED, jmxServer.getAttribute(status, "Status"));
jmxServer.invoke(status, "start", null, null);
assertEquals(true, jmxServer.getAttribute(status, "Running"));
assertEquals(StandbyStatusMBean.STATUS_RUNNING, jmxServer.getAttribute(status, "Status"));
}
assertTrue(!jmxServer.isRegistered(status));
}
Aggregations