@Test
  public void testStateStream() {
    try {
      MemoryStateBackend backend = new MemoryStateBackend();
      CheckpointStreamFactory streamFactory = backend.createStreamFactory(new JobID(), "test_op");

      HashMap<String, Integer> state = new HashMap<>();
      state.put("hey there", 2);
      state.put(
          "the crazy brown fox stumbles over a sentence that does not contain every letter", 77);

      CheckpointStreamFactory.CheckpointStateOutputStream os =
          streamFactory.createCheckpointStateOutputStream(1, 2);
      ObjectOutputStream oos = new ObjectOutputStream(os);
      oos.writeObject(state);
      oos.flush();
      StreamStateHandle handle = os.closeAndGetHandle();

      assertNotNull(handle);

      ObjectInputStream ois = new ObjectInputStream(handle.openInputStream());
      assertEquals(state, ois.readObject());
      assertTrue(ois.available() <= 0);
      ois.close();
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
  @Test
  public void testOversizedState() {
    try {
      MemoryStateBackend backend = new MemoryStateBackend(10);
      CheckpointStreamFactory streamFactory = backend.createStreamFactory(new JobID(), "test_op");

      HashMap<String, Integer> state = new HashMap<>();
      state.put("hey there", 2);
      state.put(
          "the crazy brown fox stumbles over a sentence that does not contain every letter", 77);

      try {
        CheckpointStreamFactory.CheckpointStateOutputStream outStream =
            streamFactory.createCheckpointStateOutputStream(12, 459);

        ObjectOutputStream oos = new ObjectOutputStream(outStream);
        oos.writeObject(state);

        oos.flush();

        outStream.closeAndGetHandle();

        fail("this should cause an exception");
      } catch (IOException e) {
        // now darling, isn't that exactly what we wanted?
      }
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }