use of org.apache.pulsar.functions.api.StateStore in project 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 pulsar by apache.
the class InstanceStateManager method close.
@Override
public void close() {
RuntimeException firstException = null;
for (Map.Entry<String, StateStore> entry : stores.entrySet()) {
final StateStore store = entry.getValue();
if (log.isDebugEnabled()) {
log.debug("Closing store {}", store.fqsn());
}
try {
store.close();
} catch (RuntimeException e) {
if (firstException == null) {
firstException = e;
}
log.error("Failed to close state store {}: ", store.fqsn(), e);
}
}
stores.clear();
if (null != firstException) {
throw firstException;
}
}
use of org.apache.pulsar.functions.api.StateStore in project pulsar by apache.
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 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 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());
}
Aggregations