Search in sources :

Example 11 with StateStore

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

Example 12 with StateStore

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

Example 13 with StateStore

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);
    }
}
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 14 with StateStore

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

Example 15 with StateStore

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();
}
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