Search in sources :

Example 1 with ReplicationSource

use of org.apache.hadoop.hbase.replication.regionserver.ReplicationSource in project hbase by apache.

the class TestReplicationSource method testTerminateTimeout.

/**
   * Tests that {@link ReplicationSource#terminate(String)} will timeout properly
   */
@Test
public void testTerminateTimeout() throws Exception {
    ReplicationSource source = new ReplicationSource();
    ReplicationEndpoint replicationEndpoint = new HBaseInterClusterReplicationEndpoint() {

        @Override
        protected void doStart() {
            notifyStarted();
        }

        @Override
        protected void doStop() {
        // not calling notifyStopped() here causes the caller of stop() to get a Future that never
        // completes
        }
    };
    replicationEndpoint.start();
    ReplicationPeers mockPeers = Mockito.mock(ReplicationPeers.class);
    ReplicationPeer mockPeer = Mockito.mock(ReplicationPeer.class);
    Mockito.when(mockPeer.getPeerBandwidth()).thenReturn(0L);
    Configuration testConf = HBaseConfiguration.create();
    testConf.setInt("replication.source.maxretriesmultiplier", 1);
    ReplicationSourceManager manager = Mockito.mock(ReplicationSourceManager.class);
    Mockito.when(manager.getTotalBufferUsed()).thenReturn(new AtomicLong());
    source.init(testConf, null, manager, null, mockPeers, null, "testPeer", null, replicationEndpoint, null);
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<?> future = executor.submit(new Runnable() {

        @Override
        public void run() {
            source.terminate("testing source termination");
        }
    });
    long sleepForRetries = testConf.getLong("replication.source.sleepforretries", 1000);
    Waiter.waitFor(testConf, sleepForRetries * 2, new Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return future.isDone();
        }
    });
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) ReplicationSourceManager(org.apache.hadoop.hbase.replication.regionserver.ReplicationSourceManager) AtomicLong(java.util.concurrent.atomic.AtomicLong) HBaseInterClusterReplicationEndpoint(org.apache.hadoop.hbase.replication.regionserver.HBaseInterClusterReplicationEndpoint) HBaseInterClusterReplicationEndpoint(org.apache.hadoop.hbase.replication.regionserver.HBaseInterClusterReplicationEndpoint) ExecutorService(java.util.concurrent.ExecutorService) ReplicationSource(org.apache.hadoop.hbase.replication.regionserver.ReplicationSource) Test(org.junit.Test)

Aggregations

ExecutorService (java.util.concurrent.ExecutorService)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Configuration (org.apache.hadoop.conf.Configuration)1 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)1 HBaseInterClusterReplicationEndpoint (org.apache.hadoop.hbase.replication.regionserver.HBaseInterClusterReplicationEndpoint)1 ReplicationSource (org.apache.hadoop.hbase.replication.regionserver.ReplicationSource)1 ReplicationSourceManager (org.apache.hadoop.hbase.replication.regionserver.ReplicationSourceManager)1 Test (org.junit.Test)1