Search in sources :

Example 1 with AllocationException

use of org.apache.distributedlog.bk.SimpleLedgerAllocator.AllocationException in project bookkeeper by apache.

the class TestLedgerAllocator method testAllocatorWithoutEnoughBookies.

@Test(timeout = 60000)
public void testAllocatorWithoutEnoughBookies() throws Exception {
    String allocationPath = "/allocator-without-enough-bookies";
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(conf);
    confLocal.setEnsembleSize(numBookies * 2);
    confLocal.setWriteQuorumSize(numBookies * 2);
    SimpleLedgerAllocator allocator1 = createAllocator(allocationPath, confLocal);
    allocator1.allocate();
    ZKTransaction txn1 = newTxn();
    try {
        Utils.ioResult(allocator1.tryObtain(txn1, NULL_LISTENER));
        fail("Should fail allocating ledger if there aren't enough bookies");
    } catch (AllocationException ioe) {
        // expected
        assertEquals(Phase.ERROR, ioe.getPhase());
    }
    byte[] data = zkc.get().getData(allocationPath, false, null);
    assertEquals(0, data.length);
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) ZKTransaction(org.apache.distributedlog.zk.ZKTransaction) AllocationException(org.apache.distributedlog.bk.SimpleLedgerAllocator.AllocationException) Test(org.junit.Test)

Aggregations

DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)1 AllocationException (org.apache.distributedlog.bk.SimpleLedgerAllocator.AllocationException)1 ZKTransaction (org.apache.distributedlog.zk.ZKTransaction)1 Test (org.junit.Test)1