01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.xml.impl;
17:
18: import java.util.ArrayList;
19: import java.util.List;
20:
21: import junit.framework.TestCase;
22:
23: public class BufferTest extends TestCase {
24: Buffer buffer;
25:
26: protected void setUp() throws Exception {
27: buffer = new Buffer(10);
28: }
29:
30: public void test() throws Exception {
31: Consumer consumer = new Consumer(buffer);
32: Thread thread = new Thread(consumer);
33: thread.start();
34:
35: for (int i = 0; i < 1000; i++) {
36: buffer.put(new Integer(i));
37: }
38:
39: thread.join();
40:
41: for (int i = 0; i < consumer.taken.size(); i++) {
42: Integer integer = (Integer) consumer.taken.get(i);
43: assertEquals(i, integer.intValue());
44: }
45: }
46:
47: static class Consumer implements Runnable {
48: Buffer buffer;
49: List taken;
50:
51: public Consumer(Buffer buffer) {
52: this .buffer = buffer;
53: }
54:
55: public void run() {
56: taken = new ArrayList();
57:
58: for (int i = 0; i < 1000; i++) {
59: taken.add(buffer.get());
60: }
61: }
62: }
63: }
|