use of org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore in project bookkeeper by apache.
the class TestRangeStoreImpl method setUp.
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
storageResources = StorageResources.create();
Endpoint endpoint = createEndpoint("127.0.0.1", 0);
// create the client manager
MVCCStoreFactory storeFactory = mock(MVCCStoreFactory.class);
MVCCAsyncStore<byte[], byte[]> store = mock(MVCCAsyncStore.class);
when(storeFactory.openStore(anyLong(), anyLong(), anyLong())).thenReturn(FutureUtils.value(store));
when(storeFactory.closeStores(anyLong())).thenReturn(FutureUtils.Void());
rangeStore = (RangeStoreImpl) RangeStoreBuilder.newBuilder().withStorageConfiguration(storageConf).withStorageResources(storageResources).withStorageContainerManagerFactory((numScs, storeConf, rgRegistry) -> new LocalStorageContainerManager(endpoint, storeConf, rgRegistry, 2)).withRangeStoreFactory(storeFactory).withDefaultBackendUri(URI.create("distributedlog://127.0.0.1/stream/storage")).build();
rangeStore.start();
}
use of org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore in project bookkeeper by apache.
the class MVCCStoreFactoryImpl method addStore.
private synchronized void addStore(long scId, long streamId, long rangeId, MVCCAsyncStore<byte[], byte[]> store) {
Map<RangeId, MVCCAsyncStore<byte[], byte[]>> scStores = stores.get(scId);
if (null == scStores) {
scStores = Maps.newHashMap();
}
RangeId rid = RangeId.of(streamId, rangeId);
MVCCAsyncStore<byte[], byte[]> oldStore = scStores.get(rid);
if (null != oldStore) {
store.closeAsync();
} else {
log.info("Add store (scId = {}, streamId = {}, rangeId = {})", scId, streamId, rangeId);
scStores.put(rid, store);
}
}
use of org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore in project bookkeeper by apache.
the class TableStoreCacheTest method testConcurrentOpenTableStore.
@SuppressWarnings("unchecked")
@Test
public void testConcurrentOpenTableStore() throws Exception {
MVCCAsyncStore<byte[], byte[]> mvccStore1 = mock(MVCCAsyncStore.class);
MVCCAsyncStore<byte[], byte[]> mvccStore2 = mock(MVCCAsyncStore.class);
CompletableFuture<MVCCAsyncStore<byte[], byte[]>> future1 = FutureUtils.createFuture();
CompletableFuture<MVCCAsyncStore<byte[], byte[]>> future2 = FutureUtils.createFuture();
when(factory.openStore(eq(SCID), eq(RID.getStreamId()), eq(RID.getRangeId()))).thenReturn(future1).thenReturn(future2);
CompletableFuture<TableStore> openFuture1 = storeCache.openTableStore(SCID, RID);
assertEquals(0, storeCache.getTableStores().size());
assertEquals(1, storeCache.getTableStoresOpening().size());
CompletableFuture<TableStore> openFuture2 = storeCache.openTableStore(SCID, RID);
assertEquals(0, storeCache.getTableStores().size());
assertEquals(1, storeCache.getTableStoresOpening().size());
assertSame(openFuture1, openFuture2);
future1.complete(mvccStore1);
future1.complete(mvccStore2);
TableStore store1 = FutureUtils.result(openFuture1);
TableStore store2 = FutureUtils.result(openFuture2);
assertSame(store1, store2);
assertEquals(0, storeCache.getTableStoresOpening().size());
assertEquals(1, storeCache.getTableStores().size());
assertSame(store1, storeCache.getTableStores().get(RID));
verify(factory, times(1)).openStore(eq(SCID), eq(RID.getStreamId()), eq(RID.getRangeId()));
}
Aggregations