Author: aadamchik
Date: Mon Jul 31 19:43:13 2006
New Revision: 427412
URL: http://svn.apache.org/viewvc?rev=427412&view=rev
Log:
CAY-618
Modified:
incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/main/java/org/apache/cayenne/remote/ClientChannel.java
incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/test/java/org/apache/cayenne/remote/ClientChannelTst.java
Modified:
incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/main/java/org/apache/cayenne/remote/ClientChannel.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/main/java/org/apache/cayenne/remote/ClientChannel.java?rev=427412&r1=427411&r2=427412&view=diff
==============================================================================
---
incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/main/java/org/apache/cayenne/remote/ClientChannel.java
(original)
+++
incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/main/java/org/apache/cayenne/remote/ClientChannel.java
Mon Jul 31 19:43:13 2006
@@ -42,8 +42,8 @@
import org.apache.cayenne.util.DeepMergeOperation;
/**
- * A [EMAIL PROTECTED] org.apache.cayenne.DataChannel} implementation that
accesses a remote
- * server via a ClientConnection.
+ * A [EMAIL PROTECTED] org.apache.cayenne.DataChannel} implementation that
accesses a remote server
+ * via a ClientConnection.
*
* @since 1.2
* @author Andrus Adamchik
@@ -71,12 +71,33 @@
public ClientChannel(ClientConnection connection, boolean
channelEventsEnabled,
EventManager eventManager) throws CayenneRuntimeException {
+ this(connection, channelEventsEnabled, eventManager, false);
+ }
+
+ /**
+ * @param remoteEventsOptional if true, failure to start an EventBridge
will not
+ * result in an exception.
+ * @since 3.0
+ */
+ public ClientChannel(ClientConnection connection, boolean
channelEventsEnabled,
+ EventManager eventManager, boolean remoteEventsOptional)
+ throws CayenneRuntimeException {
this.connection = connection;
this.eventManager = eventManager;
this.channelEventsEnabled = eventManager != null &&
channelEventsEnabled;
- setupRemoteChannelListener();
+ if (!remoteEventsOptional) {
+ setupRemoteChannelListener();
+ }
+ else {
+ try {
+ setupRemoteChannelListener();
+ }
+ catch (CayenneRuntimeException e) {
+
+ }
+ }
}
public EventManager getEventManager() {
@@ -109,7 +130,7 @@
List objects = response.currentList();
if (!objects.isEmpty()) {
-
+
DeepMergeOperation merger = new
DeepMergeOperation(context);
// subclass descriptors will be resolved on the
fly... here
@@ -119,7 +140,6 @@
Persistent object = (Persistent) it.next();
ObjectId id = object.getObjectId();
-
// sanity check
if (id == null) {
throw new CayenneRuntimeException(
@@ -235,8 +255,8 @@
/**
* Sends a message via connector, getting a result as an instance of a
specific class.
*
- * @throws org.apache.cayenne.client.CayenneClientException if an
underlying
- * connector exception occured, or a result is not of expected
type.
+ * @throws org.apache.cayenne.client.CayenneClientException if an
underlying connector
+ * exception occured, or a result is not of expected type.
*/
protected Object send(ClientMessage message, Class resultClass) {
Object result = connection.sendMessage(message);
Modified:
incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/test/java/org/apache/cayenne/remote/ClientChannelTst.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/test/java/org/apache/cayenne/remote/ClientChannelTst.java?rev=427412&r1=427411&r2=427412&view=diff
==============================================================================
---
incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/test/java/org/apache/cayenne/remote/ClientChannelTst.java
(original)
+++
incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/test/java/org/apache/cayenne/remote/ClientChannelTst.java
Mon Jul 31 19:43:13 2006
@@ -25,11 +25,15 @@
import java.util.List;
import org.apache.cayenne.CayenneContext;
+import org.apache.cayenne.CayenneRuntimeException;
import org.apache.cayenne.MockPersistentObject;
import org.apache.cayenne.ObjectId;
import org.apache.cayenne.PersistenceState;
import org.apache.cayenne.Persistent;
import org.apache.cayenne.QueryResponse;
+import org.apache.cayenne.event.CayenneEvent;
+import org.apache.cayenne.event.EventBridge;
+import org.apache.cayenne.event.EventManager;
import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.map.EntityResolver;
import org.apache.cayenne.map.ObjEntity;
@@ -45,8 +49,8 @@
ObjectId oid1 = new ObjectId("test_entity");
o1.setObjectId(oid1);
- MockClientConnection connection = new MockClientConnection(new
GenericResponse(Arrays
- .asList(new Object[] {
+ MockClientConnection connection = new MockClientConnection(new
GenericResponse(
+ Arrays.asList(new Object[] {
o1
})));
@@ -67,7 +71,7 @@
assertNotNull(list);
assertEquals(1, list.size());
Persistent o1_1 = (Persistent) list.get(0);
-
+
assertEquals(o1.getObjectId(), o1_1.getObjectId());
// ObjectContext must be injected
@@ -97,8 +101,8 @@
// cached object instead of the one fetched
MockPersistentObject o2 = new MockPersistentObject(oid);
- MockClientConnection connection = new MockClientConnection(new
GenericResponse(Arrays
- .asList(new Object[] {
+ MockClientConnection connection = new MockClientConnection(new
GenericResponse(
+ Arrays.asList(new Object[] {
o2
})));
@@ -135,8 +139,8 @@
// another object with the same GID ... we must merge it with cached
and return
// cached object instead of the one fetched
MockPersistentObject o2 = new MockPersistentObject(oid);
- MockClientConnection connection = new MockClientConnection(new
GenericResponse(Arrays
- .asList(new Object[] {
+ MockClientConnection connection = new MockClientConnection(new
GenericResponse(
+ Arrays.asList(new Object[] {
o2
})));
@@ -151,5 +155,51 @@
assertEquals(1, list.size());
assertTrue("Expected cached object, got: " + list, list.contains(o1));
assertSame(o1, context.getGraphManager().getNode(oid));
+ }
+
+ public void testEventBridgeFailure() throws Exception {
+ MockClientConnection connection = new MockClientConnection() {
+
+ public EventBridge getServerEventBridge() throws
CayenneRuntimeException {
+ return new EventBridge(Collections.EMPTY_LIST, "ext") {
+
+ protected void sendExternalEvent(CayenneEvent localEvent)
+ throws Exception {
+ }
+
+ protected void shutdownExternal() throws Exception {
+ }
+
+ protected void startupExternal() throws Exception {
+ // intentionally throw an exception
+ throw new CayenneRuntimeException("Test failure");
+ }
+ };
+ }
+ };
+
+ // default constructor must fail
+ try {
+ new ClientChannel(connection);
+ fail("Channel didn't throw on broken EventBridge");
+ }
+ catch (CayenneRuntimeException e) {
+ // expected
+ }
+
+ try {
+ new ClientChannel(connection, false, new EventManager(2), false);
+ fail("Channel didn't throw on broken EventBridge");
+ }
+ catch (CayenneRuntimeException e) {
+ // expected
+ }
+
+ try {
+ new ClientChannel(connection, false, new EventManager(2), true);
+ }
+ catch (CayenneRuntimeException e) {
+ fail("Channel threw on broken EventBridge");
+ }
}
}