001: /*
002: (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: TestConcurrentModificationException.java,v 1.8 2008/01/02 12:10:12 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.mem.faster.test;
008:
009: import java.util.*;
010:
011: import junit.framework.*;
012:
013: import com.hp.hpl.jena.graph.Triple;
014: import com.hp.hpl.jena.graph.query.Domain;
015: import com.hp.hpl.jena.graph.query.StageElement;
016: import com.hp.hpl.jena.mem.*;
017: import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
018:
019: public abstract class TestConcurrentModificationException extends
020: ModelTestBase {
021: public TestConcurrentModificationException(String name) {
022: super (name);
023: }
024:
025: public abstract TripleBunch getBunch();
026:
027: public static TestSuite suite() {
028: TestSuite result = new TestSuite();
029: result.addTestSuite(TestArrayBunchCME.class);
030: result.addTestSuite(TestSetBunchCME.class);
031: result.addTestSuite(TestHashedBunchCME.class);
032: return result;
033: }
034:
035: public static class TestArrayBunchCME extends
036: TestConcurrentModificationException {
037: public TestArrayBunchCME(String name) {
038: super (name);
039: }
040:
041: public TripleBunch getBunch() {
042: return new ArrayBunch();
043: }
044: }
045:
046: public static class TestSetBunchCME extends
047: TestConcurrentModificationException {
048: public TestSetBunchCME(String name) {
049: super (name);
050: }
051:
052: public TripleBunch getBunch() {
053: return new SetBunch(new ArrayBunch());
054: }
055: }
056:
057: public static class TestHashedBunchCME extends
058: TestConcurrentModificationException {
059: public TestHashedBunchCME(String name) {
060: super (name);
061: }
062:
063: public TripleBunch getBunch() {
064: return new HashedTripleBunch(new ArrayBunch());
065: }
066: }
067:
068: public void testAddThenNextThrowsCME() {
069: TripleBunch b = getBunch();
070: b.add(Triple.create("a P b"));
071: b.add(Triple.create("c Q d"));
072: Iterator it = b.iterator();
073: it.next();
074: b.add(Triple.create("change its state"));
075: try {
076: it.next();
077: fail("should have thrown ConcurrentModificationException");
078: } catch (ConcurrentModificationException e) {
079: pass();
080: }
081: }
082:
083: public void testDeleteThenNextThrowsCME() {
084: TripleBunch b = getBunch();
085: b.add(Triple.create("a P b"));
086: b.add(Triple.create("c Q d"));
087: Iterator it = b.iterator();
088: it.next();
089: b.remove(Triple.create("a P b"));
090: try {
091: it.next();
092: fail("should have thrown ConcurrentModificationException");
093: } catch (ConcurrentModificationException e) {
094: pass();
095: }
096: }
097:
098: private static final MatchOrBind mob = new MatchOrBind() {
099: public boolean matches(Triple t) {
100: return true;
101: }
102:
103: public MatchOrBind reset(Domain d) {
104: return null;
105: }
106: };
107:
108: public void testAddDuringAppThrowsCME() {
109: final TripleBunch b = getBunch();
110: b.add(Triple.create("a P b"));
111: b.add(Triple.create("c Q d"));
112: StageElement se = new StageElement() {
113: public void run(Domain current) {
114: b.add(Triple.create("S P O"));
115: }
116: };
117: try {
118: b.app(new Domain(0), se, mob);
119: fail(" should throw CME");
120: } catch (ConcurrentModificationException e) {
121: pass();
122: }
123: }
124: }
125:
126: /*
127: * (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
128: * All rights reserved.
129: *
130: * Redistribution and use in source and binary forms, with or without
131: * modification, are permitted provided that the following conditions
132: * are met:
133: * 1. Redistributions of source code must retain the above copyright
134: * notice, this list of conditions and the following disclaimer.
135: * 2. Redistributions in binary form must reproduce the above copyright
136: * notice, this list of conditions and the following disclaimer in the
137: * documentation and/or other materials provided with the distribution.
138: * 3. The name of the author may not be used to endorse or promote products
139: * derived from this software without specific prior written permission.
140: *
141: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
142: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
143: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
144: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
145: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
146: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
147: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
148: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
149: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
150: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
151: */
|