org.apache.flink.runtime.state.ArrayListSerializer Java Examples
The following examples show how to use
org.apache.flink.runtime.state.ArrayListSerializer.
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: CopyOnWriteStateTableTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * This test triggers incremental rehash and tests for corruptions. */ @Test public void testIncrementalRehash() { RegisteredKeyValueStateBackendMetaInfo<Integer, ArrayList<Integer>> metaInfo = new RegisteredKeyValueStateBackendMetaInfo<>( StateDescriptor.Type.UNKNOWN, "test", IntSerializer.INSTANCE, new ArrayListSerializer<>(IntSerializer.INSTANCE)); // we use mutable state objects. final MockInternalKeyContext<Integer> keyContext = new MockInternalKeyContext<>(IntSerializer.INSTANCE); final CopyOnWriteStateTable<Integer, Integer, ArrayList<Integer>> stateTable = new CopyOnWriteStateTable<>(keyContext, metaInfo); int insert = 0; int remove = 0; while (!stateTable.isRehashing()) { stateTable.put(insert++, 0, new ArrayList<Integer>()); if (insert % 8 == 0) { stateTable.remove(remove++, 0); } } Assert.assertEquals(insert - remove, stateTable.size()); while (stateTable.isRehashing()) { stateTable.put(insert++, 0, new ArrayList<Integer>()); if (insert % 8 == 0) { stateTable.remove(remove++, 0); } } Assert.assertEquals(insert - remove, stateTable.size()); for (int i = 0; i < insert; ++i) { if (i < remove) { Assert.assertFalse(stateTable.containsKey(i, 0)); } else { Assert.assertTrue(stateTable.containsKey(i, 0)); } } }
Example #2
Source File: CopyOnWriteStateMapTest.java From flink with Apache License 2.0 | 5 votes |
/** * This test triggers incremental rehash and tests for corruptions. */ @Test public void testIncrementalRehash() { final CopyOnWriteStateMap<Integer, Integer, ArrayList<Integer>> stateMap = new CopyOnWriteStateMap<>(new ArrayListSerializer<>(IntSerializer.INSTANCE)); int insert = 0; int remove = 0; while (!stateMap.isRehashing()) { stateMap.put(insert++, 0, new ArrayList<Integer>()); if (insert % 8 == 0) { stateMap.remove(remove++, 0); } } Assert.assertEquals(insert - remove, stateMap.size()); while (stateMap.isRehashing()) { stateMap.put(insert++, 0, new ArrayList<Integer>()); if (insert % 8 == 0) { stateMap.remove(remove++, 0); } } Assert.assertEquals(insert - remove, stateMap.size()); for (int i = 0; i < insert; ++i) { if (i < remove) { Assert.assertFalse(stateMap.containsKey(i, 0)); } else { Assert.assertTrue(stateMap.containsKey(i, 0)); } } }
Example #3
Source File: CopyOnWriteStateMapTest.java From flink with Apache License 2.0 | 5 votes |
/** * This test triggers incremental rehash and tests for corruptions. */ @Test public void testIncrementalRehash() { final CopyOnWriteStateMap<Integer, Integer, ArrayList<Integer>> stateMap = new CopyOnWriteStateMap<>(new ArrayListSerializer<>(IntSerializer.INSTANCE)); int insert = 0; int remove = 0; while (!stateMap.isRehashing()) { stateMap.put(insert++, 0, new ArrayList<>()); if (insert % 8 == 0) { stateMap.remove(remove++, 0); } } Assert.assertEquals(insert - remove, stateMap.size()); while (stateMap.isRehashing()) { stateMap.put(insert++, 0, new ArrayList<>()); if (insert % 8 == 0) { stateMap.remove(remove++, 0); } } Assert.assertEquals(insert - remove, stateMap.size()); for (int i = 0; i < insert; ++i) { if (i < remove) { Assert.assertFalse(stateMap.containsKey(i, 0)); } else { Assert.assertTrue(stateMap.containsKey(i, 0)); } } }
Example #4
Source File: CopyOnWriteStateTableTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
/** * This tests for the copy-on-write contracts, e.g. ensures that no copy-on-write is active after all snapshots are * released. */ @Test public void testCopyOnWriteContracts() { RegisteredKeyValueStateBackendMetaInfo<Integer, ArrayList<Integer>> metaInfo = new RegisteredKeyValueStateBackendMetaInfo<>( StateDescriptor.Type.UNKNOWN, "test", IntSerializer.INSTANCE, new ArrayListSerializer<>(IntSerializer.INSTANCE)); // we use mutable state objects. final MockInternalKeyContext<Integer> keyContext = new MockInternalKeyContext<>(IntSerializer.INSTANCE); final CopyOnWriteStateTable<Integer, Integer, ArrayList<Integer>> stateTable = new CopyOnWriteStateTable<>(keyContext, metaInfo); ArrayList<Integer> originalState1 = new ArrayList<>(1); ArrayList<Integer> originalState2 = new ArrayList<>(1); ArrayList<Integer> originalState3 = new ArrayList<>(1); ArrayList<Integer> originalState4 = new ArrayList<>(1); ArrayList<Integer> originalState5 = new ArrayList<>(1); originalState1.add(1); originalState2.add(2); originalState3.add(3); originalState4.add(4); originalState5.add(5); stateTable.put(1, 1, originalState1); stateTable.put(2, 1, originalState2); stateTable.put(4, 1, originalState4); stateTable.put(5, 1, originalState5); // no snapshot taken, we get the original back Assert.assertTrue(stateTable.get(1, 1) == originalState1); CopyOnWriteStateTableSnapshot<Integer, Integer, ArrayList<Integer>> snapshot1 = stateTable.stateSnapshot(); // after snapshot1 is taken, we get a copy... final ArrayList<Integer> copyState = stateTable.get(1, 1); Assert.assertFalse(copyState == originalState1); // ...and the copy is equal Assert.assertEquals(originalState1, copyState); // we make an insert AFTER snapshot1 stateTable.put(3, 1, originalState3); // on repeated lookups, we get the same copy because no further snapshot was taken Assert.assertTrue(copyState == stateTable.get(1, 1)); // we take snapshot2 CopyOnWriteStateTableSnapshot<Integer, Integer, ArrayList<Integer>> snapshot2 = stateTable.stateSnapshot(); // after the second snapshot, copy-on-write is active again for old entries Assert.assertFalse(copyState == stateTable.get(1, 1)); // and equality still holds Assert.assertEquals(copyState, stateTable.get(1, 1)); // after releasing snapshot2 stateTable.releaseSnapshot(snapshot2); // we still get the original of the untouched late insert (after snapshot1) Assert.assertTrue(originalState3 == stateTable.get(3, 1)); // but copy-on-write is still active for older inserts (before snapshot1) Assert.assertFalse(originalState4 == stateTable.get(4, 1)); // after releasing snapshot1 stateTable.releaseSnapshot(snapshot1); // no copy-on-write is active Assert.assertTrue(originalState5 == stateTable.get(5, 1)); }
Example #5
Source File: CopyOnWriteStateMapTest.java From flink with Apache License 2.0 | 4 votes |
/** * This tests for the copy-on-write contracts, e.g. ensures that no copy-on-write is active after all snapshots are * released. */ @Test public void testCopyOnWriteContracts() { final CopyOnWriteStateMap<Integer, Integer, ArrayList<Integer>> stateMap = new CopyOnWriteStateMap<>(new ArrayListSerializer<>(IntSerializer.INSTANCE)); ArrayList<Integer> originalState1 = new ArrayList<>(1); ArrayList<Integer> originalState2 = new ArrayList<>(1); ArrayList<Integer> originalState3 = new ArrayList<>(1); ArrayList<Integer> originalState4 = new ArrayList<>(1); ArrayList<Integer> originalState5 = new ArrayList<>(1); originalState1.add(1); originalState2.add(2); originalState3.add(3); originalState4.add(4); originalState5.add(5); stateMap.put(1, 1, originalState1); stateMap.put(2, 1, originalState2); stateMap.put(4, 1, originalState4); stateMap.put(5, 1, originalState5); // no snapshot taken, we get the original back Assert.assertTrue(stateMap.get(1, 1) == originalState1); CopyOnWriteStateMapSnapshot<Integer, Integer, ArrayList<Integer>> snapshot1 = stateMap.stateSnapshot(); // after snapshot1 is taken, we get a copy... final ArrayList<Integer> copyState = stateMap.get(1, 1); Assert.assertFalse(copyState == originalState1); // ...and the copy is equal Assert.assertEquals(originalState1, copyState); // we make an insert AFTER snapshot1 stateMap.put(3, 1, originalState3); // on repeated lookups, we get the same copy because no further snapshot was taken Assert.assertTrue(copyState == stateMap.get(1, 1)); // we take snapshot2 CopyOnWriteStateMapSnapshot<Integer, Integer, ArrayList<Integer>> snapshot2 = stateMap.stateSnapshot(); // after the second snapshot, copy-on-write is active again for old entries Assert.assertFalse(copyState == stateMap.get(1, 1)); // and equality still holds Assert.assertEquals(copyState, stateMap.get(1, 1)); // after releasing snapshot2 stateMap.releaseSnapshot(snapshot2); // we still get the original of the untouched late insert (after snapshot1) Assert.assertTrue(originalState3 == stateMap.get(3, 1)); // but copy-on-write is still active for older inserts (before snapshot1) Assert.assertFalse(originalState4 == stateMap.get(4, 1)); // after releasing snapshot1 stateMap.releaseSnapshot(snapshot1); // no copy-on-write is active Assert.assertTrue(originalState5 == stateMap.get(5, 1)); }
Example #6
Source File: CopyOnWriteStateMapTest.java From flink with Apache License 2.0 | 4 votes |
/** * This tests for the copy-on-write contracts, e.g. ensures that no copy-on-write is active after all snapshots are * released. */ @Test public void testCopyOnWriteContracts() { final CopyOnWriteStateMap<Integer, Integer, ArrayList<Integer>> stateMap = new CopyOnWriteStateMap<>(new ArrayListSerializer<>(IntSerializer.INSTANCE)); ArrayList<Integer> originalState1 = new ArrayList<>(1); ArrayList<Integer> originalState2 = new ArrayList<>(1); ArrayList<Integer> originalState3 = new ArrayList<>(1); ArrayList<Integer> originalState4 = new ArrayList<>(1); ArrayList<Integer> originalState5 = new ArrayList<>(1); originalState1.add(1); originalState2.add(2); originalState3.add(3); originalState4.add(4); originalState5.add(5); stateMap.put(1, 1, originalState1); stateMap.put(2, 1, originalState2); stateMap.put(4, 1, originalState4); stateMap.put(5, 1, originalState5); // no snapshot taken, we get the original back Assert.assertSame(stateMap.get(1, 1), originalState1); CopyOnWriteStateMapSnapshot<Integer, Integer, ArrayList<Integer>> snapshot1 = stateMap.stateSnapshot(); // after snapshot1 is taken, we get a copy... final ArrayList<Integer> copyState = stateMap.get(1, 1); Assert.assertNotSame(copyState, originalState1); // ...and the copy is equal Assert.assertEquals(originalState1, copyState); // we make an insert AFTER snapshot1 stateMap.put(3, 1, originalState3); // on repeated lookups, we get the same copy because no further snapshot was taken Assert.assertSame(copyState, stateMap.get(1, 1)); // we take snapshot2 CopyOnWriteStateMapSnapshot<Integer, Integer, ArrayList<Integer>> snapshot2 = stateMap.stateSnapshot(); // after the second snapshot, copy-on-write is active again for old entries Assert.assertNotSame(copyState, stateMap.get(1, 1)); // and equality still holds Assert.assertEquals(copyState, stateMap.get(1, 1)); // after releasing snapshot2 stateMap.releaseSnapshot(snapshot2); // we still get the original of the untouched late insert (after snapshot1) Assert.assertSame(originalState3, stateMap.get(3, 1)); // but copy-on-write is still active for older inserts (before snapshot1) Assert.assertNotSame(originalState4, stateMap.get(4, 1)); // after releasing snapshot1 stateMap.releaseSnapshot(snapshot1); // no copy-on-write is active Assert.assertSame(originalState5, stateMap.get(5, 1)); }