SerializableZookeeperState implements SerializableState { public <T> void set(String key, T object) throws IOException { try { Variable value = zkState.fetch(key).get(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = null; try { out = new ObjectOutputStream(bos); out.writeObject(object); value = value.mutate(bos.toByteArray()); zkState.store(value).get(); } finally { try { if (out != null) { out.close(); } } finally { bos.close(); } } } catch (InterruptedException | ExecutionException | IOException e) { throw new IOException("Unable to set zNode", e); } } SerializableZookeeperState(org.apache.mesos.state.State zkState); @SuppressWarnings("unchecked") T get(String key); void set(String key, T object); void delete(String key);  }
@Test public void testSetValid() throws IOException { serializableState.set("test", "Serializable object"); verify(state, times(1)).store(any(Variable.class)); }
@SuppressWarnings("unchecked") @Test(expected = IOException.class) public void interrupted() throws IOException { when(state.store(any(Variable.class))).thenThrow(InterruptedException.class); serializableState.set("test", "Serializable object"); }
@SuppressWarnings("unchecked") @Test(expected = IOException.class) public void executionException() throws IOException { when(state.store(any(Variable.class))).thenThrow(ExecutionException.class); serializableState.set("test", "Serializable object"); }
@SuppressWarnings("unchecked") @Test(expected = IOException.class) public void ioException() throws IOException { when(state.store(any(Variable.class))).thenThrow(IOException.class); serializableState.set("test", "Serializable object"); }