Search in sources :

Example 16 with StateStore

use of org.apache.pulsar.functions.api.StateStore in project pulsar by yahoo.

the class InstanceStateManagerTest method testGetStoreNull.

@Test
public void testGetStoreNull() {
    final String fqsn = "t/ns/store";
    StateStore getStore = stateManager.getStore("t", "ns", "store");
    assertNull(getStore);
}
Also used : StateStore(org.apache.pulsar.functions.api.StateStore) Test(org.testng.annotations.Test)

Example 17 with StateStore

use of org.apache.pulsar.functions.api.StateStore in project pulsar by yahoo.

the class InstanceStateManagerTest method testRegisterStore.

@Test
public void testRegisterStore() {
    final String fqsn = "t/ns/store";
    StateStore store = mock(StateStore.class);
    when(store.fqsn()).thenReturn(fqsn);
    this.stateManager.registerStore(store);
    StateStore getStore = stateManager.getStore("t", "ns", "store");
    assertSame(getStore, store);
}
Also used : StateStore(org.apache.pulsar.functions.api.StateStore) Test(org.testng.annotations.Test)

Example 18 with StateStore

use of org.apache.pulsar.functions.api.StateStore in project 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);
    }
}
Also used : StateStoreContextImpl(org.apache.pulsar.functions.instance.state.StateStoreContextImpl) HashMap(java.util.HashMap) StateStore(org.apache.pulsar.functions.api.StateStore) InstanceStateManager(org.apache.pulsar.functions.instance.state.InstanceStateManager) StateStoreContext(org.apache.pulsar.functions.api.StateStoreContext)

Example 19 with StateStore

use of org.apache.pulsar.functions.api.StateStore in project pulsar by apache.

the class InstanceStateManagerTest method testRegisterStore.

@Test
public void testRegisterStore() {
    final String fqsn = "t/ns/store";
    StateStore store = mock(StateStore.class);
    when(store.fqsn()).thenReturn(fqsn);
    this.stateManager.registerStore(store);
    StateStore getStore = stateManager.getStore("t", "ns", "store");
    assertSame(getStore, store);
}
Also used : StateStore(org.apache.pulsar.functions.api.StateStore) Test(org.testng.annotations.Test)

Example 20 with StateStore

use of org.apache.pulsar.functions.api.StateStore in project 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());
}
Also used : StateStore(org.apache.pulsar.functions.api.StateStore) Test(org.testng.annotations.Test)

Aggregations

StateStore (org.apache.pulsar.functions.api.StateStore)21 Test (org.testng.annotations.Test)15 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 StateStoreContext (org.apache.pulsar.functions.api.StateStoreContext)3 InstanceStateManager (org.apache.pulsar.functions.instance.state.InstanceStateManager)3 StateStoreContextImpl (org.apache.pulsar.functions.instance.state.StateStoreContextImpl)3