Search in sources :

Example 1 with OverCapacityException

use of org.apache.distributedlog.exceptions.OverCapacityException in project bookkeeper by apache.

the class TestAsyncReaderWriter method writeRecordsWithOutstandingWriteLimit.

public void writeRecordsWithOutstandingWriteLimit(int stream, int global, boolean shouldFail) throws Exception {
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(testConf);
    confLocal.setOutputBufferSize(0);
    confLocal.setImmediateFlushEnabled(true);
    confLocal.setPerWriterOutstandingWriteLimit(stream);
    confLocal.setOutstandingWriteLimitDarkmode(false);
    DistributedLogManager dlm;
    if (global > -1) {
        dlm = createNewDLM(confLocal, runtime.getMethodName(), new SimplePermitLimiter(false, global, new NullStatsLogger(), true, new FixedValueFeature("", 0)));
    } else {
        dlm = createNewDLM(confLocal, runtime.getMethodName());
    }
    BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm.startAsyncLogSegmentNonPartitioned());
    ArrayList<CompletableFuture<DLSN>> results = new ArrayList<CompletableFuture<DLSN>>(1000);
    for (int i = 0; i < 1000; i++) {
        results.add(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
    }
    for (CompletableFuture<DLSN> result : results) {
        try {
            Utils.ioResult(result);
            if (shouldFail) {
                fail("should fail due to no outstanding writes permitted");
            }
        } catch (OverCapacityException ex) {
            assertTrue(shouldFail);
        }
    }
    writer.closeAndComplete();
    dlm.close();
}
Also used : FixedValueFeature(org.apache.bookkeeper.feature.FixedValueFeature) ArrayList(java.util.ArrayList) DynamicDistributedLogConfiguration(org.apache.distributedlog.config.DynamicDistributedLogConfiguration) CompletableFuture(java.util.concurrent.CompletableFuture) NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) SimplePermitLimiter(org.apache.distributedlog.util.SimplePermitLimiter) OverCapacityException(org.apache.distributedlog.exceptions.OverCapacityException)

Example 2 with OverCapacityException

use of org.apache.distributedlog.exceptions.OverCapacityException in project bookkeeper by apache.

the class TestWriteLimiter method testGlobalOnly.

@Test(timeout = 60000)
public void testGlobalOnly() throws Exception {
    SimplePermitLimiter streamLimiter = createPermitLimiter(false, Integer.MAX_VALUE);
    SimplePermitLimiter globalLimiter = createPermitLimiter(false, 1);
    WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
    limiter.acquire();
    try {
        limiter.acquire();
        fail("should have thrown global limit exception");
    } catch (OverCapacityException ex) {
    }
    assertPermits(streamLimiter, 1, globalLimiter, 1);
    limiter.release();
    assertPermits(streamLimiter, 0, globalLimiter, 0);
}
Also used : SimplePermitLimiter(org.apache.distributedlog.util.SimplePermitLimiter) OverCapacityException(org.apache.distributedlog.exceptions.OverCapacityException) Test(org.junit.Test)

Example 3 with OverCapacityException

use of org.apache.distributedlog.exceptions.OverCapacityException in project bookkeeper by apache.

the class TestWriteLimiter method testStreamOnly.

@Test(timeout = 60000)
public void testStreamOnly() throws Exception {
    SimplePermitLimiter streamLimiter = createPermitLimiter(false, 1);
    SimplePermitLimiter globalLimiter = createPermitLimiter(false, Integer.MAX_VALUE);
    WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
    limiter.acquire();
    try {
        limiter.acquire();
        fail("should have thrown stream limit exception");
    } catch (OverCapacityException ex) {
    }
    assertPermits(streamLimiter, 1, globalLimiter, 1);
}
Also used : SimplePermitLimiter(org.apache.distributedlog.util.SimplePermitLimiter) OverCapacityException(org.apache.distributedlog.exceptions.OverCapacityException) Test(org.junit.Test)

Example 4 with OverCapacityException

use of org.apache.distributedlog.exceptions.OverCapacityException in project bookkeeper by apache.

the class TestWriteLimiter method testUnsetDisableFeatureAfterPermitsExceeded.

@Test(timeout = 60000)
public void testUnsetDisableFeatureAfterPermitsExceeded() throws Exception {
    SettableFeature feature = new SettableFeature("test", 10000);
    SimplePermitLimiter streamLimiter = createPermitLimiter(false, 1, feature);
    SimplePermitLimiter globalLimiter = createPermitLimiter(false, Integer.MAX_VALUE, feature);
    WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
    limiter.acquire();
    limiter.acquire();
    limiter.acquire();
    limiter.acquire();
    assertPermits(streamLimiter, 4, globalLimiter, 4);
    feature.set(0);
    limiter.release();
    assertPermits(streamLimiter, 3, globalLimiter, 3);
    try {
        limiter.acquire();
        fail("should have thrown stream limit exception");
    } catch (OverCapacityException ex) {
    }
    assertPermits(streamLimiter, 3, globalLimiter, 3);
    limiter.release();
    limiter.release();
    limiter.release();
    assertPermits(streamLimiter, 0, globalLimiter, 0);
}
Also used : SimplePermitLimiter(org.apache.distributedlog.util.SimplePermitLimiter) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) OverCapacityException(org.apache.distributedlog.exceptions.OverCapacityException) Test(org.junit.Test)

Example 5 with OverCapacityException

use of org.apache.distributedlog.exceptions.OverCapacityException in project bookkeeper by apache.

the class TestWriteLimiter method testUnsetDisableFeatureBeforePermitsExceeded.

@Test(timeout = 60000)
public void testUnsetDisableFeatureBeforePermitsExceeded() throws Exception {
    SettableFeature feature = new SettableFeature("test", 0);
    SimplePermitLimiter streamLimiter = createPermitLimiter(false, 1, feature);
    SimplePermitLimiter globalLimiter = createPermitLimiter(false, Integer.MAX_VALUE, feature);
    WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
    limiter.acquire();
    try {
        limiter.acquire();
        fail("should have thrown stream limit exception");
    } catch (OverCapacityException ex) {
    }
    assertPermits(streamLimiter, 1, globalLimiter, 1);
    feature.set(10000);
    limiter.acquire();
    assertPermits(streamLimiter, 2, globalLimiter, 2);
}
Also used : SimplePermitLimiter(org.apache.distributedlog.util.SimplePermitLimiter) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) OverCapacityException(org.apache.distributedlog.exceptions.OverCapacityException) Test(org.junit.Test)

Aggregations

OverCapacityException (org.apache.distributedlog.exceptions.OverCapacityException)5 SimplePermitLimiter (org.apache.distributedlog.util.SimplePermitLimiter)5 Test (org.junit.Test)4 SettableFeature (org.apache.bookkeeper.feature.SettableFeature)2 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 FixedValueFeature (org.apache.bookkeeper.feature.FixedValueFeature)1 NullStatsLogger (org.apache.bookkeeper.stats.NullStatsLogger)1 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)1 DynamicDistributedLogConfiguration (org.apache.distributedlog.config.DynamicDistributedLogConfiguration)1