Example usage for org.apache.commons.lang SerializationException SerializationException

List of usage examples for org.apache.commons.lang SerializationException SerializationException

Introduction

In this page you can find the example usage for org.apache.commons.lang SerializationException SerializationException.

Prototype

public SerializationException() 

Source Link

Document

Constructs a new SerializationException without specified detail message.

Usage

From source file:com.gemstone.gemfire.distributed.internal.membership.gms.messenger.JGroupsMessengerJUnitTest.java

@Test
public void testSerializationError() throws Exception {
    for (int i = 0; i < 2; i++) {
        boolean enableMcast = (i == 1);
        initMocks(enableMcast);//from   w  ww  .  j a v a2  s.c o  m
        InternalDistributedMember mbr = createAddress(8888);
        DistributedCacheOperation.CacheOperationMessage msg = mock(
                DistributedCacheOperation.CacheOperationMessage.class);
        when(msg.getRecipients()).thenReturn(new InternalDistributedMember[] { mbr });
        when(msg.getMulticast()).thenReturn(enableMcast);
        if (!enableMcast) {
            // for non-mcast we send a message with a reply-processor
            when(msg.getProcessorId()).thenReturn(1234);
        } else {
            // for mcast we send a direct-ack message and expect the messenger
            // to register it
            stub(msg.isDirectAck()).toReturn(true);
        }
        when(msg.getDSFID()).thenReturn((int) DataSerializableFixedID.PUT_ALL_MESSAGE);

        // for code coverage we need to test with both a SerializationException and
        // an IOException.  The former is wrapped in a GemfireIOException while the
        // latter is not
        doThrow(new SerializationException()).when(msg).toData(any(DataOutput.class));
        try {
            messenger.send(msg);
            fail("expected a failure");
        } catch (GemFireIOException e) {
            // success
        }
        if (enableMcast) {
            verify(msg, atLeastOnce()).registerProcessor();
        }
        doThrow(new IOException()).when(msg).toData(any(DataOutput.class));
        try {
            messenger.send(msg);
            fail("expected a failure");
        } catch (GemFireIOException e) {
            // success
        }
    }
}

From source file:org.apache.geode.distributed.internal.membership.gms.messenger.JGroupsMessengerJUnitTest.java

@Test
public void testSerializationError() throws Exception {
    for (int i = 0; i < 2; i++) {
        boolean enableMcast = (i == 1);
        initMocks(enableMcast);/*from   w  w  w. jav  a2  s  . c o  m*/
        InternalDistributedMember mbr = createAddress(8888);
        DistributedCacheOperation.CacheOperationMessage msg = mock(
                DistributedCacheOperation.CacheOperationMessage.class);
        when(msg.getRecipients()).thenReturn(new InternalDistributedMember[] { mbr });
        when(msg.getMulticast()).thenReturn(enableMcast);
        if (!enableMcast) {
            // for non-mcast we send a message with a reply-processor
            when(msg.getProcessorId()).thenReturn(1234);
        } else {
            // for mcast we send a direct-ack message and expect the messenger
            // to register it
            stub(msg.isDirectAck()).toReturn(true);
        }
        when(msg.getDSFID()).thenReturn((int) DataSerializableFixedID.PUT_ALL_MESSAGE);

        // for code coverage we need to test with both a SerializationException and
        // an IOException. The former is wrapped in a GemfireIOException while the
        // latter is not
        doThrow(new SerializationException()).when(msg).toData(any(DataOutput.class));
        try {
            messenger.send(msg);
            fail("expected a failure");
        } catch (GemFireIOException e) {
            // success
        }
        if (enableMcast) {
            verify(msg, atLeastOnce()).registerProcessor();
        }
        doThrow(new IOException()).when(msg).toData(any(DataOutput.class));
        try {
            messenger.send(msg);
            fail("expected a failure");
        } catch (GemFireIOException e) {
            // success
        }
    }
}

From source file:org.apache.ibatis.cache.TransactionalCacheManager.java

/**
 * ?//w  w w  . j ava 2  s. c  o m
 * @param ?
 * @return   ??
 * @throws CloneNotSupportedException
 */
@SuppressWarnings("unchecked")
public static <T> T cloneObject(T obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }
    if (obj instanceof Cloneable) {//implement Cloneable?clone
        Class<? extends Object> clazz = obj.getClass();
        Method m;
        try {
            m = clazz.getMethod("clone", (Class[]) null);
        } catch (NoSuchMethodException ex) {
            throw new NoSuchMethodError(ex.getMessage());
        }
        try {
            Object result = m.invoke(obj, (Object[]) null);
            return (T) result;
        } catch (InvocationTargetException ex) {
            Throwable cause = ex.getCause();
            if (cause instanceof CloneNotSupportedException) {
                throw ((CloneNotSupportedException) cause);
            }
            throw new Error("Unexpected exception", cause);
        } catch (IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        }
    }
    if (obj instanceof Serializable)//??????
        return (T) SerializationUtils.clone((Serializable) obj);
    throw new SerializationException();
}