Java Code Examples for org.apache.flink.api.common.state.ListState#update()

The following examples show how to use org.apache.flink.api.common.state.ListState#update() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StateBackendTestBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * This test verifies that all ListState implementations are consistent in not allowing
 * {@link ListState#addAll(List)} to be called with {@code null}.
 */
@Test
public void testListStateUpdateNull() throws Exception {
	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(
				VoidNamespace.INSTANCE,
				VoidNamespaceSerializer.INSTANCE,
				stateDescr);

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		expectedException.expect(NullPointerException.class);
		state.update(null);
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 2
Source File: StateBackendTestBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Verify that an empty {@code ListState} yields {@code null}.
 */
@Test
public void testListStateDefaultValue() throws Exception {
	AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);

	ListStateDescriptor<String> kvId = new ListStateDescriptor<>("id", String.class);

	ListState<String> state = backend.getPartitionedState(
			VoidNamespace.INSTANCE,
			VoidNamespaceSerializer.INSTANCE, kvId);

	backend.setCurrentKey(1);
	assertNull(state.get());

	state.update(Arrays.asList("Ciao", "Bello"));
	assertThat(state.get(), containsInAnyOrder("Ciao", "Bello"));

	state.clear();
	assertNull(state.get());

	backend.dispose();
}
 
Example 3
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This test verifies that all ListState implementations are consistent in not allowing
 * {@link ListState#addAll(List)} to be called with {@code null}.
 */
@Test
public void testListStateUpdateNull() throws Exception {
	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(
				VoidNamespace.INSTANCE,
				VoidNamespaceSerializer.INSTANCE,
				stateDescr);

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		expectedException.expect(NullPointerException.class);
		state.update(null);
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 4
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Verify that an empty {@code ListState} yields {@code null}.
 */
@Test
public void testListStateDefaultValue() throws Exception {
	AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);

	ListStateDescriptor<String> kvId = new ListStateDescriptor<>("id", String.class);

	ListState<String> state = backend.getPartitionedState(
			VoidNamespace.INSTANCE,
			VoidNamespaceSerializer.INSTANCE, kvId);

	backend.setCurrentKey(1);
	assertNull(state.get());

	state.update(Arrays.asList("Ciao", "Bello"));
	assertThat(state.get(), containsInAnyOrder("Ciao", "Bello"));

	state.clear();
	assertNull(state.get());

	backend.dispose();
}
 
Example 5
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This test verifies that all ListState implementations are consistent in not allowing
 * {@link ListState#addAll(List)} to be called with {@code null}.
 */
@Test
public void testListStateUpdateNull() throws Exception {
	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(
				VoidNamespace.INSTANCE,
				VoidNamespaceSerializer.INSTANCE,
				stateDescr);

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		expectedException.expect(NullPointerException.class);
		state.update(null);
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 6
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Verify that an empty {@code ListState} yields {@code null}.
 */
@Test
public void testListStateDefaultValue() throws Exception {
	AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);

	ListStateDescriptor<String> kvId = new ListStateDescriptor<>("id", String.class);

	ListState<String> state = backend.getPartitionedState(
			VoidNamespace.INSTANCE,
			VoidNamespaceSerializer.INSTANCE, kvId);

	backend.setCurrentKey(1);
	assertNull(state.get());

	state.update(Arrays.asList("Ciao", "Bello"));
	assertThat(state.get(), containsInAnyOrder("Ciao", "Bello"));

	state.clear();
	assertNull(state.get());

	backend.dispose();
}
 
Example 7
Source File: StateBackendTestBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * This test verifies that all ListState implementations are consistent in not allowing
 * {@link ListState#addAll(List)} to be called with {@code null} entries in the list of entries
 * to add.
 */
@Test
public void testListStateUpdateNullEntries() throws Exception {
	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(
				VoidNamespace.INSTANCE,
				VoidNamespaceSerializer.INSTANCE,
				stateDescr);

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		expectedException.expect(NullPointerException.class);

		List<Long> adding = new ArrayList<>();
		adding.add(3L);
		adding.add(null);
		adding.add(5L);
		state.update(adding);
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 8
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * This test verifies that all ListState implementations are consistent in not allowing
 * {@link ListState#addAll(List)} to be called with {@code null} entries in the list of entries
 * to add.
 */
@Test
public void testListStateUpdateNullEntries() throws Exception {
	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(
				VoidNamespace.INSTANCE,
				VoidNamespaceSerializer.INSTANCE,
				stateDescr);

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		expectedException.expect(NullPointerException.class);

		List<Long> adding = new ArrayList<>();
		adding.add(3L);
		adding.add(null);
		adding.add(5L);
		state.update(adding);
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 9
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * This test verifies that all ListState implementations are consistent in not allowing
 * {@link ListState#addAll(List)} to be called with {@code null} entries in the list of entries
 * to add.
 */
@Test
public void testListStateUpdateNullEntries() throws Exception {
	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(
				VoidNamespace.INSTANCE,
				VoidNamespaceSerializer.INSTANCE,
				stateDescr);

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		expectedException.expect(NullPointerException.class);

		List<Long> adding = new ArrayList<>();
		adding.add(3L);
		adding.add(null);
		adding.add(5L);
		state.update(adding);
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 10
Source File: StateBackendTestBase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testListStateAPIs() throws Exception {

	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, stateDescr);

		keyedBackend.setCurrentKey("def");
		assertNull(state.get());
		state.add(17L);
		state.add(11L);
		assertThat(state.get(), containsInAnyOrder(17L, 11L));
		// update(emptyList) should remain the value null
		state.update(Collections.emptyList());
		assertNull(state.get());
		state.update(Arrays.asList(10L, 16L));
		assertThat(state.get(), containsInAnyOrder(16L, 10L));
		assertThat(state.get(), containsInAnyOrder(16L, 10L));

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		assertNull(state.get());
		assertNull(state.get());
		state.addAll(Collections.emptyList());
		assertNull(state.get());
		state.addAll(Arrays.asList(3L, 4L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		state.addAll(new ArrayList<>());
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		state.addAll(Arrays.asList(5L, 6L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));
		state.addAll(new ArrayList<>());
		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));

		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));
		state.update(Arrays.asList(1L, 2L));
		assertThat(state.get(), containsInAnyOrder(1L, 2L));

		keyedBackend.setCurrentKey("def");
		assertThat(state.get(), containsInAnyOrder(10L, 16L));
		state.clear();
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		state.add(3L);
		state.add(2L);
		state.add(1L);

		keyedBackend.setCurrentKey("def");
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		assertThat(state.get(), containsInAnyOrder(1L, 2L, 3L, 2L, 1L));
		state.update(Arrays.asList(5L, 6L));
		assertThat(state.get(), containsInAnyOrder(5L, 6L));
		state.clear();

		// make sure all lists / maps are cleared
		assertThat("State backend is not empty.", keyedBackend.numKeyValueStateEntries(), is(0));
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 11
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testListStateAPIs() throws Exception {

	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, stateDescr);

		keyedBackend.setCurrentKey("def");
		assertNull(state.get());
		state.add(17L);
		state.add(11L);
		assertThat(state.get(), containsInAnyOrder(17L, 11L));
		// update(emptyList) should remain the value null
		state.update(Collections.emptyList());
		assertNull(state.get());
		state.update(Arrays.asList(10L, 16L));
		assertThat(state.get(), containsInAnyOrder(16L, 10L));
		assertThat(state.get(), containsInAnyOrder(16L, 10L));

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		assertNull(state.get());
		assertNull(state.get());
		state.addAll(Collections.emptyList());
		assertNull(state.get());
		state.addAll(Arrays.asList(3L, 4L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		state.addAll(new ArrayList<>());
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		state.addAll(Arrays.asList(5L, 6L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));
		state.addAll(new ArrayList<>());
		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));

		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));
		state.update(Arrays.asList(1L, 2L));
		assertThat(state.get(), containsInAnyOrder(1L, 2L));

		keyedBackend.setCurrentKey("def");
		assertThat(state.get(), containsInAnyOrder(10L, 16L));
		state.clear();
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		state.add(3L);
		state.add(2L);
		state.add(1L);

		keyedBackend.setCurrentKey("def");
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		assertThat(state.get(), containsInAnyOrder(1L, 2L, 3L, 2L, 1L));
		state.update(Arrays.asList(5L, 6L));
		assertThat(state.get(), containsInAnyOrder(5L, 6L));
		state.clear();

		// make sure all lists / maps are cleared
		assertThat("State backend is not empty.", keyedBackend.numKeyValueStateEntries(), is(0));
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}
 
Example 12
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testListStateAPIs() throws Exception {

	AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE);

	final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);

	try {
		ListState<Long> state =
			keyedBackend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, stateDescr);

		keyedBackend.setCurrentKey("def");
		assertNull(state.get());
		state.add(17L);
		state.add(11L);
		assertThat(state.get(), containsInAnyOrder(17L, 11L));
		// update(emptyList) should remain the value null
		state.update(Collections.emptyList());
		assertNull(state.get());
		state.update(Arrays.asList(10L, 16L));
		assertThat(state.get(), containsInAnyOrder(16L, 10L));
		assertThat(state.get(), containsInAnyOrder(16L, 10L));

		keyedBackend.setCurrentKey("abc");
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		assertNull(state.get());
		assertNull(state.get());
		state.addAll(Collections.emptyList());
		assertNull(state.get());
		state.addAll(Arrays.asList(3L, 4L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		state.addAll(new ArrayList<>());
		assertThat(state.get(), containsInAnyOrder(3L, 4L));
		state.addAll(Arrays.asList(5L, 6L));
		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));
		state.addAll(new ArrayList<>());
		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));

		assertThat(state.get(), containsInAnyOrder(3L, 4L, 5L, 6L));
		state.update(Arrays.asList(1L, 2L));
		assertThat(state.get(), containsInAnyOrder(1L, 2L));

		keyedBackend.setCurrentKey("def");
		assertThat(state.get(), containsInAnyOrder(10L, 16L));
		state.clear();
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		state.add(3L);
		state.add(2L);
		state.add(1L);

		keyedBackend.setCurrentKey("def");
		assertNull(state.get());

		keyedBackend.setCurrentKey("g");
		assertThat(state.get(), containsInAnyOrder(1L, 2L, 3L, 2L, 1L));
		state.update(Arrays.asList(5L, 6L));
		assertThat(state.get(), containsInAnyOrder(5L, 6L));
		state.clear();

		// make sure all lists / maps are cleared
		assertThat("State backend is not empty.", keyedBackend.numKeyValueStateEntries(), is(0));
	} finally {
		keyedBackend.close();
		keyedBackend.dispose();
	}
}