You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by ro...@apache.org on 2006/10/20 18:06:48 UTC
svn commit: r466167 -
/incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/ConcurrencyTest.java
Author: rooneg
Date: Fri Oct 20 09:06:47 2006
New Revision: 466167
URL: http://svn.apache.org/viewvc?view=rev&rev=466167
Log:
Add a new test for some concurrency issues that show up in 0.1.0 but are
fixed in trunk.
Submitted by: Ugo Cei <ugo apache.org>
(Tweaked by me.)
Issue: ABDERA-12
[ in parser/src/test/java/org/apache/abdera/test/parser/stax ]
* ConcurrencyTest.java: New test.
Added:
incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/ConcurrencyTest.java (with props)
Added: incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/ConcurrencyTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/ConcurrencyTest.java?view=auto&rev=466167
==============================================================================
--- incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/ConcurrencyTest.java (added)
+++ incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/ConcurrencyTest.java Fri Oct 20 09:06:47 2006
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera.test.parser.stax;
+
+import junit.framework.TestCase;
+
+import java.io.InputStream;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.parser.Parser;
+
+
+/**
+ * Test possible concurrency issues.
+ *
+ * @version $Id$
+ */
+public class ConcurrencyTest extends TestCase {
+
+ private static final int N_THREADS = 100;
+
+ /**
+ * Test for a concurrency issue that caused a ConcurrentModificationException
+ * in Abdera 0.1.0 but seems to be fixed in 0.2. We leave the test here to
+ * prevent possible regressions.
+ */
+ public void testSetContentMT() throws Exception {
+ Thread t[] = new Thread[N_THREADS];
+ final boolean failed[] = new boolean[t.length];
+ for (int i = 0 ; i < t.length ; ++i) {
+ final int j = i;
+ failed[i] = false;
+ Runnable r = new Runnable() {
+ public void run() {
+ try {
+ setContent();
+ } catch (Exception e) {
+ e.printStackTrace();
+ failed[j] = true;
+ fail(e.toString());
+ }
+ }
+ };
+ t[i] = new Thread(r);
+ t[i].start();
+ }
+ for (int i = 0 ; i < t.length ; ++i) {
+ t[i].join();
+ if (failed[i]) {
+ fail("Thread " + t[i] + " failed.");
+ }
+ }
+ }
+
+ private void setContent() throws Exception {
+ // For Abdera 0.1.0 this would be:
+ // Parser parser = Factory.INSTANCE.newParser();
+ Parser parser = Abdera.getNewParser();
+ InputStream is = ParserTest.class.getResourceAsStream("/entry.xml");
+ Document<Entry> doc = parser.parse(is);
+ Entry entry = doc.getRoot();
+ Content content = entry.getFactory().newContent(Content.Type.XML);
+ content.setValue("<some><xml>document</xml></some>");
+ content.setMimeType("application/xml");
+ entry.setContentElement(content);
+ }
+}
Propchange: incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/ConcurrencyTest.java
------------------------------------------------------------------------------
svn:keywords = Id