Search in sources :

Example 1 with ThrottleSourceListener

use of io.pravega.segmentstore.storage.ThrottleSourceListener in project pravega by pravega.

the class BookKeeperLogTests method testDebugLogWrapper.

/**
 * Tests {@link BookKeeperLogFactory#createDebugLogWrapper}.
 */
@Test
public void testDebugLogWrapper() throws Exception {
    @Cleanup val wrapper = this.factory.get().createDebugLogWrapper(0);
    val readOnly = wrapper.asReadOnly();
    val writeSettings = readOnly.getWriteSettings();
    Assert.assertEquals(BookKeeperConfig.MAX_APPEND_LENGTH, writeSettings.getMaxWriteLength());
    Assert.assertEquals((int) BookKeeperConfig.BK_WRITE_TIMEOUT.getDefaultValue(), writeSettings.getMaxWriteTimeout().toMillis());
    Assert.assertEquals((int) BookKeeperConfig.MAX_OUTSTANDING_BYTES.getDefaultValue(), writeSettings.getMaxOutstandingBytes());
    AssertExtensions.assertThrows("registerQueueStateChangeListener should not be implemented.", () -> readOnly.registerQueueStateChangeListener(new ThrottleSourceListener() {

        @Override
        public void notifyThrottleSourceChanged() {
        }

        @Override
        public boolean isClosed() {
            return false;
        }
    }), ex -> ex instanceof UnsupportedOperationException);
}
Also used : lombok.val(lombok.val) ThrottleSourceListener(io.pravega.segmentstore.storage.ThrottleSourceListener) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 2 with ThrottleSourceListener

use of io.pravega.segmentstore.storage.ThrottleSourceListener in project pravega by pravega.

the class InMemoryDurableDataLogTests method testRegisterQueueStateListener.

@Override
@Test
public void testRegisterQueueStateListener() {
    @Cleanup val log = createDurableDataLog();
    // Following should have no effect.
    log.registerQueueStateChangeListener(new ThrottleSourceListener() {

        @Override
        public void notifyThrottleSourceChanged() {
        }

        @Override
        public boolean isClosed() {
            return false;
        }
    });
}
Also used : lombok.val(lombok.val) ThrottleSourceListener(io.pravega.segmentstore.storage.ThrottleSourceListener) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 3 with ThrottleSourceListener

use of io.pravega.segmentstore.storage.ThrottleSourceListener in project pravega by pravega.

the class CacheUtilizationProviderTests method testCleanupListeners.

/**
 * Tests the {@link CacheUtilizationProvider#registerCleanupListener} and {@link CacheUtilizationProvider#notifyCleanupListeners}
 */
@Test
public void testCleanupListeners() {
    val usedBytes = new AtomicLong();
    val cup = new CacheUtilizationProvider(POLICY, usedBytes::get);
    TestCleanupListener l1 = new TestCleanupListener();
    TestCleanupListener l2 = new TestCleanupListener();
    cup.registerCleanupListener(l1);
    cup.registerCleanupListener(l2);
    cup.notifyCleanupListeners();
    Assert.assertEquals("Expected cleanup listener to be invoked the first time.", 1, l1.getCallCount());
    Assert.assertEquals("Expected cleanup listener to be invoked the first time.", 1, l2.getCallCount());
    l2.setClosed(true);
    cup.notifyCleanupListeners();
    Assert.assertEquals("Expected cleanup listener to be invoked the second time.", 2, l1.getCallCount());
    Assert.assertEquals("Not expected cleanup listener to be invoked the second time.", 1, l2.getCallCount());
    // This should have no effect.
    cup.registerCleanupListener(l2);
    // Now verify with errors.
    cup.registerCleanupListener(new ThrottleSourceListener() {

        @Override
        public void notifyThrottleSourceChanged() {
            throw new IntentionalException();
        }

        @Override
        public boolean isClosed() {
            return false;
        }
    });
    cup.notifyCleanupListeners();
    Assert.assertEquals("Expected cleanup listener to be invoked the third time.", 3, l1.getCallCount());
    Assert.assertEquals("Not expected cleanup listener to be invoked the third time.", 1, l2.getCallCount());
}
Also used : lombok.val(lombok.val) AtomicLong(java.util.concurrent.atomic.AtomicLong) ThrottleSourceListener(io.pravega.segmentstore.storage.ThrottleSourceListener) IntentionalException(io.pravega.test.common.IntentionalException) Test(org.junit.Test)

Aggregations

ThrottleSourceListener (io.pravega.segmentstore.storage.ThrottleSourceListener)3 lombok.val (lombok.val)3 Test (org.junit.Test)3 Cleanup (lombok.Cleanup)2 IntentionalException (io.pravega.test.common.IntentionalException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1