Search in sources :

Example 6 with StateStore

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

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;
    }
}
Also used : StateStore(org.apache.pulsar.functions.api.StateStore) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 7 with StateStore

use of org.apache.pulsar.functions.api.StateStore in project incubator-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;
    }
}
Also used : StateStore(org.apache.pulsar.functions.api.StateStore) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 8 with StateStore

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

Example 9 with StateStore

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

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 10 with StateStore

use of org.apache.pulsar.functions.api.StateStore in project incubator-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)

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