Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-10-04 06:36:19 +0000
committerEike Stepper2010-10-04 06:36:19 +0000
commit4ec0947627e385c5f699cb00617f9dfe5074fc6d (patch)
tree2b8046fe51db1596e999efacf97e37d3dbc40f73 /plugins/org.eclipse.net4j.tests
parent203df07f1bf73234d8b994960a9e731c9486ffda (diff)
downloadcdo-4ec0947627e385c5f699cb00617f9dfe5074fc6d.tar.gz
cdo-4ec0947627e385c5f699cb00617f9dfe5074fc6d.tar.xz
cdo-4ec0947627e385c5f699cb00617f9dfe5074fc6d.zip
[284307] Add support for streaming of large byte arrays / BLOB
https://bugs.eclipse.org/bugs/show_bug.cgi?id=284307
Diffstat (limited to 'plugins/org.eclipse.net4j.tests')
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java2
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExpectedIOTest.java390
2 files changed, 392 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
index 6af6be85b5..230fda1993 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
@@ -12,6 +12,7 @@ package org.eclipse.net4j.tests;
import org.eclipse.net4j.tests.bugzilla.Bugzilla_241463_Test;
import org.eclipse.net4j.tests.bugzilla.Bugzilla_262875_Test;
+import org.eclipse.net4j.util.tests.ExpectedIOTest;
import org.eclipse.net4j.util.tests.ExtendedIOTest;
import org.eclipse.net4j.util.tests.MultiMapTest;
import org.eclipse.net4j.util.tests.QueueWorkerWorkSerializerTest;
@@ -49,6 +50,7 @@ public class AllTests
suite.addTestSuite(ExceptionTest.class);
suite.addTestSuite(SecurityTest.class);
suite.addTestSuite(QueueWorkerWorkSerializerTest.class);
+ suite.addTestSuite(ExpectedIOTest.class);
// Bugzillas
suite.addTestSuite(Bugzilla_241463_Test.class);
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExpectedIOTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExpectedIOTest.java
new file mode 100644
index 0000000000..fd613300a3
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExpectedIOTest.java
@@ -0,0 +1,390 @@
+/**
+ * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
+import org.eclipse.net4j.util.io.ExpectedFileInputStream;
+import org.eclipse.net4j.util.io.ExpectedFileReader;
+import org.eclipse.net4j.util.io.IOUtil;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * @author Eike Stepper
+ */
+public class ExpectedIOTest extends AbstractOMTest
+{
+ private Exception exception;
+
+ @Override
+ protected void doSetUp() throws Exception
+ {
+ super.doSetUp();
+ exception = null;
+ }
+
+ public void testInputStream() throws Exception
+ {
+ final File file = File.createTempFile("ExpectedIOTest", ".tmp");
+ final int LOOPS = 30;
+
+ Thread producer = new Thread("PRODUCER")
+ {
+ @Override
+ public void run()
+ {
+ DataOutputStream out = null;
+
+ try
+ {
+ out = new DataOutputStream(new FileOutputStream(file));
+ for (int i = 0; i < LOOPS; i++)
+ {
+ out.writeInt(i);
+ System.err.println(i);
+ ConcurrencyUtil.sleep(100);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(out);
+ }
+ }
+ };
+
+ Thread consumer = new Thread("CONSUMER")
+ {
+ @Override
+ public void run()
+ {
+ DataInputStream in = null;
+
+ try
+ {
+ in = new DataInputStream(new ExpectedFileInputStream(file, LOOPS * 4));
+
+ for (int i = 0; i < LOOPS; i++)
+ {
+ System.out.println(in.readInt());
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(in);
+ }
+ }
+ };
+
+ producer.start();
+ ConcurrencyUtil.sleep(500);
+ consumer.start();
+
+ producer.join();
+ consumer.join();
+
+ if (exception != null)
+ {
+ throw exception;
+ }
+ }
+
+ public void testInputStreamEOF() throws Exception
+ {
+ final File file = File.createTempFile("ExpectedIOTest", ".tmp");
+ final int LOOPS = 30;
+
+ Thread producer = new Thread("PRODUCER")
+ {
+ @Override
+ public void run()
+ {
+ DataOutputStream out = null;
+
+ try
+ {
+ out = new DataOutputStream(new FileOutputStream(file));
+ for (int i = 0; i < LOOPS; i++)
+ {
+ out.writeInt(i);
+ System.err.println(i);
+ ConcurrencyUtil.sleep(100);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(out);
+ }
+ }
+ };
+
+ Thread consumer = new Thread("CONSUMER")
+ {
+ @Override
+ public void run()
+ {
+ DataInputStream in = null;
+
+ try
+ {
+ in = new DataInputStream(new ExpectedFileInputStream(file, LOOPS * 4));
+
+ for (int i = 0; i < LOOPS + 10; i++)
+ {
+ System.out.println(in.readInt());
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(in);
+ }
+ }
+ };
+
+ producer.start();
+ ConcurrencyUtil.sleep(500);
+ consumer.start();
+
+ producer.join();
+ consumer.join();
+
+ if (!(exception instanceof EOFException))
+ {
+ throw exception;
+ }
+ }
+
+ public void testReader() throws Exception
+ {
+ final File file = File.createTempFile("ExpectedIOTest", ".tmp");
+ final int LOOPS = 30;
+
+ Thread producer = new Thread("PRODUCER")
+ {
+ @Override
+ public void run()
+ {
+ Writer out = null;
+
+ try
+ {
+ out = new FileWriter(file);
+ for (int i = 0; i < LOOPS; i++)
+ {
+ int c = 'a' + i;
+ out.write(c);
+ System.err.println(c);
+
+ out.write(c + 1);
+ System.err.println(c + 1);
+ ConcurrencyUtil.sleep(100);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(out);
+ }
+ }
+ };
+
+ Thread consumer = new Thread("CONSUMER")
+ {
+ @Override
+ public void run()
+ {
+ Reader in = null;
+
+ try
+ {
+ in = new ExpectedFileReader(file, LOOPS * 2);
+
+ for (int i = 0; i < LOOPS; i++)
+ {
+ int c = in.read();
+ if (c == -1)
+ {
+ throw new EOFException();
+ }
+
+ System.out.println(c);
+ c = in.read();
+ if (c == -1)
+ {
+ throw new EOFException();
+ }
+
+ System.out.println(c);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(in);
+ }
+ }
+ };
+
+ producer.start();
+ ConcurrencyUtil.sleep(500);
+ consumer.start();
+
+ producer.join();
+ consumer.join();
+
+ if (exception != null)
+ {
+ throw exception;
+ }
+ }
+
+ public void testReaderEOF() throws Exception
+ {
+ final File file = File.createTempFile("ExpectedIOTest", ".tmp");
+ final int LOOPS = 30;
+
+ Thread producer = new Thread("PRODUCER")
+ {
+ @Override
+ public void run()
+ {
+ Writer out = null;
+
+ try
+ {
+ out = new FileWriter(file);
+ for (int i = 0; i < LOOPS; i++)
+ {
+ int c = 'a' + i;
+ out.write(c);
+ System.err.println(c);
+
+ out.write(c + 1);
+ System.err.println(c + 1);
+ ConcurrencyUtil.sleep(100);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(out);
+ }
+ }
+ };
+
+ Thread consumer = new Thread("CONSUMER")
+ {
+ @Override
+ public void run()
+ {
+ Reader in = null;
+
+ try
+ {
+ in = new ExpectedFileReader(file, LOOPS * 2);
+
+ for (int i = 0; i < LOOPS + 10; i++)
+ {
+ int c = in.read();
+ if (c == -1)
+ {
+ throw new EOFException();
+ }
+
+ System.out.println(c);
+ c = in.read();
+ if (c == -1)
+ {
+ throw new EOFException();
+ }
+
+ System.out.println(c);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(in);
+ }
+ }
+ };
+
+ producer.start();
+ ConcurrencyUtil.sleep(500);
+ consumer.start();
+
+ producer.join();
+ consumer.join();
+
+ if (!(exception instanceof EOFException))
+ {
+ throw exception;
+ }
+ }
+}

Back to the top