Search in sources :

Example 26 with NotSerializableException

use of java.io.NotSerializableException in project orientdb by orientechnologies.

the class TrackedListTest method testSerialization.

/**
   * Test that {@link OTrackedList} is serialised correctly.
   */
@Test
public void testSerialization() throws Exception {
    class NotSerializableDocument extends ODocument {

        private static final long serialVersionUID = 1L;

        private void writeObject(ObjectOutputStream oos) throws IOException {
            throw new NotSerializableException();
        }
    }
    final OTrackedList<String> beforeSerialization = new OTrackedList<String>(new NotSerializableDocument());
    beforeSerialization.add("firstVal");
    beforeSerialization.add("secondVal");
    final OMemoryStream memoryStream = new OMemoryStream();
    ObjectOutputStream out = new ObjectOutputStream(memoryStream);
    out.writeObject(beforeSerialization);
    out.close();
    final ObjectInputStream input = new ObjectInputStream(new OMemoryInputStream(memoryStream.copy()));
    @SuppressWarnings("unchecked") final List<String> afterSerialization = (List<String>) input.readObject();
    Assert.assertEquals(afterSerialization.size(), beforeSerialization.size(), "List size");
    for (int i = 0; i < afterSerialization.size(); i++) {
        Assert.assertEquals(afterSerialization.get(i), beforeSerialization.get(i));
    }
}
Also used : OMemoryInputStream(com.orientechnologies.orient.core.serialization.OMemoryInputStream) OMemoryStream(com.orientechnologies.orient.core.serialization.OMemoryStream) ObjectOutputStream(java.io.ObjectOutputStream) NotSerializableException(java.io.NotSerializableException) ArrayList(java.util.ArrayList) List(java.util.List) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ObjectInputStream(java.io.ObjectInputStream) Test(org.testng.annotations.Test)

Example 27 with NotSerializableException

use of java.io.NotSerializableException in project orientdb by orientechnologies.

the class TrackedSetTest method testSetSerialization.

/**
   * Test that {@link OTrackedSet} is serialised correctly.
   */
@Test
public void testSetSerialization() throws Exception {
    class NotSerializableDocument extends ODocument {

        private static final long serialVersionUID = 1L;

        private void writeObject(ObjectOutputStream oos) throws IOException {
            throw new NotSerializableException();
        }
    }
    final OTrackedSet<String> beforeSerialization = new OTrackedSet<String>(new NotSerializableDocument());
    beforeSerialization.add("firstVal");
    beforeSerialization.add("secondVal");
    final OMemoryStream memoryStream = new OMemoryStream();
    ObjectOutputStream out = new ObjectOutputStream(memoryStream);
    out.writeObject(beforeSerialization);
    out.close();
    final ObjectInputStream input = new ObjectInputStream(new OMemoryInputStream(memoryStream.copy()));
    @SuppressWarnings("unchecked") final Set<String> afterSerialization = (Set<String>) input.readObject();
    Assert.assertEquals(afterSerialization.size(), beforeSerialization.size(), "Set size");
    Assert.assertTrue(beforeSerialization.containsAll(afterSerialization));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) OMemoryInputStream(com.orientechnologies.orient.core.serialization.OMemoryInputStream) OMemoryStream(com.orientechnologies.orient.core.serialization.OMemoryStream) ObjectOutputStream(java.io.ObjectOutputStream) NotSerializableException(java.io.NotSerializableException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ObjectInputStream(java.io.ObjectInputStream) Test(org.testng.annotations.Test)

Example 28 with NotSerializableException

use of java.io.NotSerializableException in project flink by apache.

the class FailedCheckpointStatsTest method testIsJavaSerializable.

@Test
public void testIsJavaSerializable() throws Exception {
    long duration = 123912931293L;
    long triggerTimestamp = 10123;
    long failureTimestamp = triggerTimestamp + duration;
    Map<JobVertexID, TaskStateStats> taskStats = new HashMap<>();
    JobVertexID jobVertexId = new JobVertexID();
    taskStats.put(jobVertexId, new TaskStateStats(jobVertexId, 1));
    FailedCheckpointStats failed = new FailedCheckpointStats(123123123L, triggerTimestamp, CheckpointProperties.forStandardCheckpoint(), 1337, taskStats, 3, 190890123, 0, failureTimestamp, null, new NotSerializableException("message"));
    FailedCheckpointStats copy = CommonTestUtils.createCopySerializable(failed);
    assertEquals(failed.getCheckpointId(), copy.getCheckpointId());
    assertEquals(failed.getTriggerTimestamp(), copy.getTriggerTimestamp());
    assertEquals(failed.getProperties(), copy.getProperties());
    assertEquals(failed.getNumberOfSubtasks(), copy.getNumberOfSubtasks());
    assertEquals(failed.getNumberOfAcknowledgedSubtasks(), copy.getNumberOfAcknowledgedSubtasks());
    assertEquals(failed.getEndToEndDuration(), copy.getEndToEndDuration());
    assertEquals(failed.getStateSize(), copy.getStateSize());
    assertEquals(failed.getLatestAcknowledgedSubtaskStats(), copy.getLatestAcknowledgedSubtaskStats());
    assertEquals(failed.getStatus(), copy.getStatus());
    assertEquals(failed.getFailureMessage(), copy.getFailureMessage());
}
Also used : NotSerializableException(java.io.NotSerializableException) HashMap(java.util.HashMap) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) Test(org.junit.Test)

Example 29 with NotSerializableException

use of java.io.NotSerializableException in project dubbo by alibaba.

the class AbstractSerializationPersionFailTest method test_PersonListList.

@Test
public void test_PersonListList() throws Exception {
    List<List<Person>> args = new ArrayList<List<Person>>();
    List<Person> sublist = new ArrayList<Person>();
    sublist.add(new Person());
    args.add(sublist);
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(args);
        fail();
    } catch (NotSerializableException expected) {
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString("Serialized class com.alibaba.dubbo.common.model.Person must implement java.io.Serializable"));
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Person(com.alibaba.dubbo.common.model.Person) Test(org.junit.Test)

Example 30 with NotSerializableException

use of java.io.NotSerializableException in project dubbo by alibaba.

the class AbstractSerializationPersionFailTest method test_PersonList.

@Test
public void test_PersonList() throws Exception {
    List<Person> args = new ArrayList<Person>();
    args.add(new Person());
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(args);
        fail();
    } catch (NotSerializableException expected) {
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString("Serialized class com.alibaba.dubbo.common.model.Person must implement java.io.Serializable"));
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) ArrayList(java.util.ArrayList) Person(com.alibaba.dubbo.common.model.Person) Test(org.junit.Test)

Aggregations

NotSerializableException (java.io.NotSerializableException)39 ObjectOutputStream (java.io.ObjectOutputStream)14 IOException (java.io.IOException)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ObjectInputStream (java.io.ObjectInputStream)9 Test (org.junit.Test)9 Person (com.alibaba.dubbo.common.model.Person)7 ObjectOutput (com.alibaba.dubbo.common.serialize.ObjectOutput)7 ArrayList (java.util.ArrayList)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Serializable (java.io.Serializable)6 HashMap (java.util.HashMap)5 InvalidClassException (java.io.InvalidClassException)4 OptionalDataException (java.io.OptionalDataException)4 StreamCorruptedException (java.io.StreamCorruptedException)4 List (java.util.List)4 CancelException (org.apache.geode.CancelException)4 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 OMemoryInputStream (com.orientechnologies.orient.core.serialization.OMemoryInputStream)3