Search in sources :

Example 1 with NetworkErrorProxy

use of org.apache.jackrabbit.oak.segment.test.proxy.NetworkErrorProxy in project jackrabbit-oak by apache.

the class BrokenNetworkIT method useProxy.

private void useProxy(boolean ssl, int skipPosition, int skipBytes, int flipPosition, boolean intermediateChange) throws Exception {
    FileStore serverStore = serverFileStore.fileStore();
    FileStore clientStore = clientFileStore1.fileStore();
    NodeStore store = SegmentNodeStoreBuilders.builder(serverStore).build();
    addTestContent(store, "server");
    serverStore.flush();
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), serverStore, MB, ssl)) {
        serverSync.start();
        File spoolFolder = folder.newFolder();
        try (NetworkErrorProxy ignored = new NetworkErrorProxy(proxyPort.getPort(), getServerHost(), serverPort.getPort(), flipPosition, skipPosition, skipBytes);
            StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), proxyPort.getPort(), clientStore, ssl, getClientTimeout(), false, spoolFolder)) {
            clientSync.run();
        }
        assertFalse("stores are equal", serverStore.getHead().equals(clientStore.getHead()));
        if (intermediateChange) {
            addTestContent(store, "server2");
            serverStore.flush();
        }
        try (StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), serverPort.getPort(), clientStore, ssl, getClientTimeout(), false, spoolFolder)) {
            clientSync.run();
        }
    }
    assertEquals("stores are not equal", serverStore.getHead(), clientStore.getHead());
}
Also used : TemporaryFileStore(org.apache.jackrabbit.oak.segment.test.TemporaryFileStore) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) StandbyServerSync(org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync) StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) File(java.io.File) NetworkErrorProxy(org.apache.jackrabbit.oak.segment.test.proxy.NetworkErrorProxy)

Example 2 with NetworkErrorProxy

use of org.apache.jackrabbit.oak.segment.test.proxy.NetworkErrorProxy in project jackrabbit-oak by apache.

the class DataStoreTestBase method useProxy.

private void useProxy(int skipPosition, int skipBytes, int flipPosition, boolean intermediateChange) throws Exception {
    int blobSize = 5 * MB;
    FileStore primary = getPrimary();
    FileStore secondary = getSecondary();
    NodeStore store = SegmentNodeStoreBuilders.builder(primary).build();
    byte[] data = addTestContent(store, "server", blobSize);
    primary.flush();
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), primary, MB)) {
        serverSync.start();
        File spoolFolder = folder.newFolder();
        try (NetworkErrorProxy ignored = new NetworkErrorProxy(proxyPort.getPort(), getServerHost(), serverPort.getPort(), flipPosition, skipPosition, skipBytes);
            StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), proxyPort.getPort(), secondary, false, getClientTimeout(), false, spoolFolder)) {
            clientSync.run();
        }
        if (storesShouldBeDifferent()) {
            assertFalse("stores are equal", primary.getHead().equals(secondary.getHead()));
        }
        if (intermediateChange) {
            blobSize = 2 * MB;
            data = addTestContent(store, "server", blobSize);
            primary.flush();
        }
        try (StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), serverPort.getPort(), secondary, false, getClientTimeout(), false, spoolFolder)) {
            clientSync.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());
    byte[] testData = new byte[blobSize];
    try (InputStream blobInputStream = b.getNewStream()) {
        ByteStreams.readFully(blobInputStream, testData);
        assertArrayEquals(data, testData);
    }
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) Blob(org.apache.jackrabbit.oak.api.Blob) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) StandbyServerSync(org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) File(java.io.File) NetworkErrorProxy(org.apache.jackrabbit.oak.segment.test.proxy.NetworkErrorProxy) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Aggregations

File (java.io.File)2 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)2 StandbyClientSync (org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync)2 StandbyServerSync (org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync)2 NetworkErrorProxy (org.apache.jackrabbit.oak.segment.test.proxy.NetworkErrorProxy)2 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Blob (org.apache.jackrabbit.oak.api.Blob)1 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)1 TemporaryFileStore (org.apache.jackrabbit.oak.segment.test.TemporaryFileStore)1