@Override public void go() throws Exception { serializer.serialize("a value", lockingOut); } };
@Override public void copy(DataInputView source, DataOutputView target) throws IOException { if (CONCURRENT_ACCESS_CHECK) { enterExclusiveThread(); } try { checkKryoInitialized(); if (this.copyInstance == null){ this.copyInstance = createInstance(); } T tmp = deserialize(copyInstance, source); serialize(tmp, target); } finally { if (CONCURRENT_ACCESS_CHECK) { exitExclusiveThread(); } } }
serializer.serialize(str, target); fail("should throw a java.io.EOFException");
serializer.serialize(i, target);
@Test public void testConcurrentUseOfSerializer() throws Exception { final KryoSerializer<String> serializer = new KryoSerializer<>(String.class, new ExecutionConfig()); final BlockerSync sync = new BlockerSync(); final DataOutputView regularOut = new DataOutputSerializer(32); final DataOutputView lockingOut = new LockingView(sync); // this thread serializes and gets stuck there final CheckedThread thread = new CheckedThread("serializer") { @Override public void go() throws Exception { serializer.serialize("a value", lockingOut); } }; thread.start(); sync.awaitBlocker(); // this should fail with an exception try { serializer.serialize("value", regularOut); fail("should have failed with an exception"); } catch (IllegalStateException e) { // expected } finally { // release the thread that serializes sync.releaseBlocker(); } // this propagates exceptions from the spawned thread thread.sync(); }
@Override public void copy(DataInputView source, DataOutputView target) throws IOException { if (CONCURRENT_ACCESS_CHECK) { enterExclusiveThread(); } try { checkKryoInitialized(); if (this.copyInstance == null){ this.copyInstance = createInstance(); } T tmp = deserialize(copyInstance, source); serialize(tmp, target); } finally { if (CONCURRENT_ACCESS_CHECK) { exitExclusiveThread(); } } }
@Override public void copy(DataInputView source, DataOutputView target) throws IOException { if (CONCURRENT_ACCESS_CHECK) { enterExclusiveThread(); } try { checkKryoInitialized(); if (this.copyInstance == null){ this.copyInstance = createInstance(); } T tmp = deserialize(copyInstance, source); serialize(tmp, target); } finally { if (CONCURRENT_ACCESS_CHECK) { exitExclusiveThread(); } } }