use of org.apache.pulsar.functions.api.StateStore in project incubator-pulsar by apache.
the class InstanceStateManagerTest method testClose.
@Test
public void testClose() {
final String fqsn1 = "t/ns/store-1";
StateStore store1 = mock(StateStore.class);
when(store1.fqsn()).thenReturn(fqsn1);
final String fqsn2 = "t/ns/store-2";
StateStore store2 = mock(StateStore.class);
when(store2.fqsn()).thenReturn(fqsn2);
this.stateManager.registerStore(store1);
this.stateManager.registerStore(store2);
this.stateManager.close();
verify(store1, times(1)).close();
verify(store2, times(1)).close();
}
use of org.apache.pulsar.functions.api.StateStore in project incubator-pulsar by apache.
the class InstanceStateManagerTest method testCloseException.
@Test
public void testCloseException() {
final String fqsn1 = "t/ns/store-1";
StateStore store1 = mock(StateStore.class);
when(store1.fqsn()).thenReturn(fqsn1);
RuntimeException exception1 = new RuntimeException("exception 1");
doThrow(exception1).when(store1).close();
final String fqsn2 = "t/ns/store-2";
StateStore store2 = mock(StateStore.class);
when(store2.fqsn()).thenReturn(fqsn2);
RuntimeException exception2 = new RuntimeException("exception 2");
doThrow(exception2).when(store2).close();
this.stateManager.registerStore(store2);
this.stateManager.registerStore(store1);
try {
this.stateManager.close();
fail("Should fail to close the state manager");
} catch (RuntimeException re) {
assertSame(re, exception2);
}
assertTrue(this.stateManager.isEmpty());
}
use of org.apache.pulsar.functions.api.StateStore in project incubator-pulsar by apache.
the class JavaInstanceRunnable method setupStateStore.
private void setupStateStore() throws Exception {
this.stateManager = new InstanceStateManager();
if (null == stateStorageServiceUrl) {
stateStoreProvider = StateStoreProvider.NULL;
} else {
stateStoreProvider = getStateStoreProvider();
Map<String, Object> stateStoreProviderConfig = new HashMap<>();
stateStoreProviderConfig.put(BKStateStoreProviderImpl.STATE_STORAGE_SERVICE_URL, stateStorageServiceUrl);
stateStoreProvider.init(stateStoreProviderConfig, instanceConfig.getFunctionDetails());
StateStore store = stateStoreProvider.getStateStore(instanceConfig.getFunctionDetails().getTenant(), instanceConfig.getFunctionDetails().getNamespace(), instanceConfig.getFunctionDetails().getName());
StateStoreContext context = new StateStoreContextImpl();
store.init(context);
stateManager.registerStore(store);
}
}
use of org.apache.pulsar.functions.api.StateStore in project pulsar by yahoo.
the class InstanceStateManagerTest method testRegisterStoreTwice.
@Test
public void testRegisterStoreTwice() {
final String fqsn = "t/ns/store";
StateStore store = mock(StateStore.class);
when(store.fqsn()).thenReturn(fqsn);
this.stateManager.registerStore(store);
try {
this.stateManager.registerStore(store);
fail("Should fail to register a store twice");
} catch (IllegalArgumentException iae) {
// expected
}
}
use of org.apache.pulsar.functions.api.StateStore in project pulsar by yahoo.
the class InstanceStateManagerTest method testClose.
@Test
public void testClose() {
final String fqsn1 = "t/ns/store-1";
StateStore store1 = mock(StateStore.class);
when(store1.fqsn()).thenReturn(fqsn1);
final String fqsn2 = "t/ns/store-2";
StateStore store2 = mock(StateStore.class);
when(store2.fqsn()).thenReturn(fqsn2);
this.stateManager.registerStore(store1);
this.stateManager.registerStore(store2);
this.stateManager.close();
verify(store1, times(1)).close();
verify(store2, times(1)).close();
}
Aggregations