Search in sources :

Example 1 with IndexReplicationHandler

use of org.apache.lucene.replicator.IndexReplicationHandler in project lucene-solr by apache.

the class HttpReplicatorTest method testServerErrors.

@Test
public void testServerErrors() throws Exception {
    // tests the behaviour of the client when the server sends an error
    // must use BasicClientConnectionManager to test whether the client is closed correctly
    BasicHttpClientConnectionManager conMgr = new BasicHttpClientConnectionManager();
    Replicator replicator = new HttpReplicator(host, port, ReplicationService.REPLICATION_CONTEXT + "/s1", conMgr);
    ReplicationClient client = new ReplicationClient(replicator, new IndexReplicationHandler(handlerIndexDir, null), new PerSessionDirectoryFactory(clientWorkDir));
    try {
        publishRevision(5);
        try {
            replicationServlet.setRespondWithError(true);
            client.updateNow();
            fail("expected exception");
        } catch (Throwable t) {
        // expected
        }
        replicationServlet.setRespondWithError(false);
        // now it should work
        client.updateNow();
        reopenReader();
        assertEquals(5, Integer.parseInt(reader.getIndexCommit().getUserData().get("ID"), 16));
        client.close();
    } finally {
        replicationServlet.setRespondWithError(false);
    }
}
Also used : PerSessionDirectoryFactory(org.apache.lucene.replicator.PerSessionDirectoryFactory) Replicator(org.apache.lucene.replicator.Replicator) LocalReplicator(org.apache.lucene.replicator.LocalReplicator) IndexReplicationHandler(org.apache.lucene.replicator.IndexReplicationHandler) ReplicationClient(org.apache.lucene.replicator.ReplicationClient) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager) Test(org.junit.Test)

Example 2 with IndexReplicationHandler

use of org.apache.lucene.replicator.IndexReplicationHandler in project lucene-solr by apache.

the class HttpReplicatorTest method testBasic.

@Test
public void testBasic() throws Exception {
    Replicator replicator = new HttpReplicator(host, port, ReplicationService.REPLICATION_CONTEXT + "/s1", getClientConnectionManager());
    ReplicationClient client = new ReplicationClient(replicator, new IndexReplicationHandler(handlerIndexDir, null), new PerSessionDirectoryFactory(clientWorkDir));
    publishRevision(1);
    client.updateNow();
    reopenReader();
    assertEquals(1, Integer.parseInt(reader.getIndexCommit().getUserData().get("ID"), 16));
    publishRevision(2);
    client.updateNow();
    reopenReader();
    assertEquals(2, Integer.parseInt(reader.getIndexCommit().getUserData().get("ID"), 16));
    client.close();
}
Also used : PerSessionDirectoryFactory(org.apache.lucene.replicator.PerSessionDirectoryFactory) Replicator(org.apache.lucene.replicator.Replicator) LocalReplicator(org.apache.lucene.replicator.LocalReplicator) IndexReplicationHandler(org.apache.lucene.replicator.IndexReplicationHandler) ReplicationClient(org.apache.lucene.replicator.ReplicationClient) Test(org.junit.Test)

Aggregations

IndexReplicationHandler (org.apache.lucene.replicator.IndexReplicationHandler)2 LocalReplicator (org.apache.lucene.replicator.LocalReplicator)2 PerSessionDirectoryFactory (org.apache.lucene.replicator.PerSessionDirectoryFactory)2 ReplicationClient (org.apache.lucene.replicator.ReplicationClient)2 Replicator (org.apache.lucene.replicator.Replicator)2 Test (org.junit.Test)2 BasicHttpClientConnectionManager (org.apache.http.impl.conn.BasicHttpClientConnectionManager)1