You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2013/10/21 18:46:15 UTC
git commit: CAMEL-6866: Fixed ConcurrentModificationException when
starting QuickFIX/J component with more than one engine.
Updated Branches:
refs/heads/master 92b291074 -> 8b9e0fd8c
CAMEL-6866: Fixed ConcurrentModificationException when starting QuickFIX/J component with more than one engine.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8b9e0fd8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8b9e0fd8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8b9e0fd8
Branch: refs/heads/master
Commit: 8b9e0fd8ce9a4cbf95e252b1b02816170e612690
Parents: 92b2910
Author: Babak Vahdat <bv...@apache.org>
Authored: Mon Oct 21 18:45:59 2013 +0200
Committer: Babak Vahdat <bv...@apache.org>
Committed: Mon Oct 21 18:45:59 2013 +0200
----------------------------------------------------------------------
.../component/quickfixj/QuickfixjComponent.java | 2 +-
.../quickfixj/QuickfixjComponentTest.java | 47 ++++++++++++--------
2 files changed, 29 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/8b9e0fd8/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfixj/QuickfixjComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfixj/QuickfixjComponent.java b/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfixj/QuickfixjComponent.java
index 9e9c7f1..03b89cd 100644
--- a/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfixj/QuickfixjComponent.java
+++ b/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfixj/QuickfixjComponent.java
@@ -163,8 +163,8 @@ public class QuickfixjComponent extends DefaultComponent implements StartupListe
for (Map.Entry<String, QuickfixjEngine> entry : provisionalEngines.entrySet()) {
startQuickfixjEngine(entry.getValue());
engines.put(entry.getKey(), entry.getValue());
- provisionalEngines.remove(entry.getKey());
}
+ provisionalEngines.clear();
}
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/8b9e0fd8/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfixj/QuickfixjComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfixj/QuickfixjComponentTest.java b/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfixj/QuickfixjComponentTest.java
index ca3ab79..532a9b6 100644
--- a/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfixj/QuickfixjComponentTest.java
+++ b/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfixj/QuickfixjComponentTest.java
@@ -38,12 +38,12 @@ import org.apache.camel.StatefulService;
import org.apache.camel.component.quickfixj.converter.QuickfixjConverters;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.converter.StaticMethodTypeConverter;
+import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ServiceHelper;
import org.apache.mina.common.TransportType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-
import quickfix.Acceptor;
import quickfix.DefaultMessageFactory;
import quickfix.FixVersions;
@@ -63,7 +63,6 @@ import quickfix.field.SenderCompID;
import quickfix.field.Subject;
import quickfix.field.TargetCompID;
import quickfix.fix44.Email;
-
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
@@ -72,7 +71,9 @@ import static org.junit.Assert.assertTrue;
public class QuickfixjComponentTest {
private File settingsFile;
+ private File settingsFile2;
private File tempdir;
+ private File tempdir2;
private ClassLoader contextClassLoader;
private SessionID sessionID;
private SessionSettings settings;
@@ -99,8 +100,10 @@ public class QuickfixjComponentTest {
@Before
public void setUp() throws Exception {
settingsFile = File.createTempFile("quickfixj_test_", ".cfg");
+ settingsFile2 = File.createTempFile("quickfixj_test2_", ".cfg");
tempdir = settingsFile.getParentFile();
- URL[] urls = new URL[] {tempdir.toURI().toURL()};
+ tempdir2 = settingsFile.getParentFile();
+ URL[] urls = new URL[] {tempdir.toURI().toURL(), tempdir2.toURI().toURL()};
sessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "FOO", "BAR");
@@ -138,7 +141,7 @@ public class QuickfixjComponentTest {
assertThat(component.getEngines().size(), is(0));
Method converterMethod = QuickfixjConverters.class.getMethod("toSessionID", new Class<?>[] {String.class});
- camelContext.getTypeConverterRegistry().addTypeConverter(SessionID.class, String.class, new StaticMethodTypeConverter(converterMethod));
+ camelContext.getTypeConverterRegistry().addTypeConverter(SessionID.class, String.class, new StaticMethodTypeConverter(converterMethod, false));
}
@After
@@ -159,30 +162,36 @@ public class QuickfixjComponentTest {
settings.setString(sessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.INITIATOR_CONNECTION_TYPE);
settings.setLong(sessionID, Initiator.SETTING_SOCKET_CONNECT_PORT, 1234);
- writeSettings();
+ writeSettings(settings, true);
+ // Should use cached QFJ engine
Endpoint e1 = component.createEndpoint(getEndpointUri(settingsFile.getName(), null));
assertThat(component.getProvisionalEngines().size(), is(1));
assertThat(component.getProvisionalEngines().get(settingsFile.getName()), is(notNullValue()));
assertThat(component.getProvisionalEngines().get(settingsFile.getName()).isStarted(), is(false));
+ assertThat(component.getEngines().size(), is(0));
assertThat(((QuickfixjEndpoint)e1).getSessionID(), is(nullValue()));
-
- // Should used cached QFJ engine
- Endpoint e2 = component.createEndpoint(getEndpointUri(settingsFile.getName(), sessionID));
-
- assertThat(component.getProvisionalEngines().size(), is(1));
+
+ writeSettings(settings, false);
+
+ // Should use cached QFJ engine
+ Endpoint e2 = component.createEndpoint(getEndpointUri(settingsFile2.getName(), null));
+ assertThat(component.getProvisionalEngines().size(), is(2));
assertThat(component.getProvisionalEngines().get(settingsFile.getName()), is(notNullValue()));
assertThat(component.getProvisionalEngines().get(settingsFile.getName()).isStarted(), is(false));
- assertThat(((QuickfixjEndpoint)e2).getSessionID(), is(sessionID));
+ assertThat(component.getEngines().size(), is(0));
+ assertThat(((QuickfixjEndpoint)e2).getSessionID(), is(nullValue()));
// will start the component
camelContext.start();
assertThat(component.getProvisionalEngines().size(), is(0));
- assertThat(component.getEngines().size(), is(1));
+ assertThat(component.getEngines().size(), is(2));
assertThat(component.getEngines().get(settingsFile.getName()).isStarted(), is(true));
// Move these too an endpoint testcase if one exists
+ assertThat(e1.isSingleton(), is(true));
+ assertThat(((MultipleConsumersSupport)e1).isMultipleConsumersSupported(), is(true));
assertThat(e2.isSingleton(), is(true));
assertThat(((MultipleConsumersSupport)e2).isMultipleConsumersSupported(), is(true));
}
@@ -203,14 +212,14 @@ public class QuickfixjComponentTest {
assertThat(component.getEngines().size(), is(1));
assertThat(component.getEngines().get(settingsFile.getName()), is(notNullValue()));
assertThat(component.getEngines().get(settingsFile.getName()).isStarted(), is(true));
+ assertThat(component.getProvisionalEngines().size(), is(0));
assertThat(((QuickfixjEndpoint)e1).getSessionID(), is(nullValue()));
- // Should used cached QFJ engine
Endpoint e2 = component.createEndpoint(getEndpointUri(settingsFile.getName(), sessionID));
-
assertThat(component.getEngines().size(), is(1));
assertThat(component.getEngines().get(settingsFile.getName()), is(notNullValue()));
assertThat(component.getEngines().get(settingsFile.getName()).isStarted(), is(true));
+ assertThat(component.getProvisionalEngines().size(), is(0));
assertThat(((QuickfixjEndpoint)e2).getSessionID(), is(sessionID));
}
@@ -274,7 +283,7 @@ public class QuickfixjComponentTest {
settings.setLong(initiatorSessionID, Initiator.SETTING_RECONNECT_INTERVAL, 1);
setSessionID(settings, initiatorSessionID);
- writeSettings(settings);
+ writeSettings(settings, true);
Endpoint endpoint = component.createEndpoint(getEndpointUri(settingsFile.getName(), null));
@@ -346,15 +355,15 @@ public class QuickfixjComponentTest {
}
private void writeSettings() throws IOException {
- writeSettings(settings);
+ writeSettings(settings, true);
}
- private void writeSettings(SessionSettings settings) throws IOException {
- FileOutputStream settingsOut = new FileOutputStream(settingsFile);
+ private void writeSettings(SessionSettings settings, boolean firstSettingsFile) throws IOException {
+ FileOutputStream settingsOut = new FileOutputStream(firstSettingsFile ? settingsFile : settingsFile2);
try {
settings.toStream(settingsOut);
} finally {
- settingsOut.close();
+ IOHelper.close(settingsOut);
}
}
}