Author: rmannibucau
Date: Wed Aug  1 12:52:08 2012
New Revision: 1367968

URL: http://svn.apache.org/viewvc?rev=1367968&view=rev
Log:
TOMEE-345 header + a test on serialization of ejbtimerimpl

Added:
    
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/timer/EjbTimerImplSerializableTest.java
Modified:
    
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/timer/CalendarTimerData.java
    
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/ThisInConstructorTest.java

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/timer/CalendarTimerData.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/timer/CalendarTimerData.java?rev=1367968&r1=1367967&r2=1367968&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/timer/CalendarTimerData.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/timer/CalendarTimerData.java
 Wed Aug  1 12:52:08 2012
@@ -51,7 +51,7 @@ public class CalendarTimerData extends T
             return new EJBCronTrigger(scheduleExpression);
         } catch (ParseException e) {
             //TODO how to handle the ParseException
-            throw new IllegalArgumentException("Fail to parse schedule 
expression " + scheduleExpression);
+            throw new IllegalArgumentException("Fail to parse schedule 
expression " + scheduleExpression, e);
         }
     }
 

Modified: 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/ThisInConstructorTest.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/ThisInConstructorTest.java?rev=1367968&r1=1367967&r2=1367968&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/ThisInConstructorTest.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/ThisInConstructorTest.java
 Wed Aug  1 12:52:08 2012
@@ -1,3 +1,19 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.openejb.core.stateless;
 
 import org.apache.openejb.jee.Empty;

Added: 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/timer/EjbTimerImplSerializableTest.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/timer/EjbTimerImplSerializableTest.java?rev=1367968&view=auto
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/timer/EjbTimerImplSerializableTest.java
 (added)
+++ 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/timer/EjbTimerImplSerializableTest.java
 Wed Aug  1 12:52:08 2012
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.timer;
+
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.core.timer.EjbTimerService;
+import org.apache.openejb.core.timer.EjbTimerServiceImpl;
+import org.apache.openejb.jee.Empty;
+import org.apache.openejb.jee.StatelessBean;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.junit.Module;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ejb.EJB;
+import javax.ejb.Schedule;
+import javax.ejb.Stateless;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.lang.reflect.Field;
+
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+@RunWith(ApplicationComposer.class)
+public class EjbTimerImplSerializableTest {
+    @Test
+    public void serializeDeserialize() throws Exception {
+        final BeanContext context = 
SystemInstance.get().getComponent(ContainerSystem.class).getBeanContext("EJBWithTimer");
+        final EjbTimerService timer = context.getEjbTimerService();
+        assertNotNull(timer);
+        assertThat(timer, instanceOf(EjbTimerServiceImpl.class));
+
+        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        final ObjectOutputStream oos = new ObjectOutputStream(baos);
+        oos.writeObject(timer);
+
+        final ByteArrayInputStream bais = new 
ByteArrayInputStream(baos.toByteArray());
+        final ObjectInputStream ois = new ObjectInputStream(bais);
+        final EjbTimerService timerDeserialized = (EjbTimerService) 
ois.readObject();
+        assertThat(timerDeserialized, instanceOf(EjbTimerServiceImpl.class));
+
+        assertEqualsByReflection(timer, timerDeserialized, "deployment");
+        assertEqualsByReflection(timer, timerDeserialized, "transacted");
+        assertEqualsByReflection(timer, timerDeserialized, "retryAttempts");
+    }
+
+    private void assertEqualsByReflection(final EjbTimerService timer, final 
EjbTimerService timerDeserialized, final String name) throws Exception {
+        final Field field = EjbTimerServiceImpl.class.getDeclaredField(name);
+        field.setAccessible(true);
+
+        final Object v1 = field.get(timer);
+        final Object v2 = field.get(timerDeserialized);
+
+        assertEquals(name, v1, v2);
+    }
+
+    @EJB
+    private EJBWithTimer stateless;
+
+    @Module
+    public StatelessBean bean() {
+        final StatelessBean bean = new StatelessBean(EJBWithTimer.class);
+        bean.setLocalBean(new Empty());
+        return bean;
+    }
+
+    @Stateless
+    public static class EJBWithTimer {
+        // no need to run it, we just want a timer
+        @Schedule
+        public void doSthg() {
+            // no-op
+        }
+    }
+}


Reply via email to