aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2011-03-15 15:21:38 (EDT)
committerGlyn Normington2011-03-15 15:21:38 (EDT)
commitab0f2c9183d64a4f7fe2593f4715b501e273dda9 (patch)
tree1f798276549008c7af2084e7b7af531f784467be
parentc095ad6432f4459f1e08970bbab6d09652f68196 (diff)
downloadorg.eclipse.virgo.kernel-ab0f2c9183d64a4f7fe2593f4715b501e273dda9.zip
org.eclipse.virgo.kernel-ab0f2c9183d64a4f7fe2593f4715b501e273dda9.tar.gz
org.eclipse.virgo.kernel-ab0f2c9183d64a4f7fe2593f4715b501e273dda9.tar.bz2
Test multiple digraph saves/loads to same stream.
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphPeristenceTests.java29
1 files changed, 20 insertions, 9 deletions
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphPeristenceTests.java b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphPeristenceTests.java
index f93c9f8..7d9d23f 100644
--- a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphPeristenceTests.java
+++ b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphPeristenceTests.java
@@ -37,7 +37,6 @@ import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
@@ -55,8 +54,6 @@ public class StandardRegionDigraphPeristenceTests {
private static final Collection<String> regionNames = Arrays.asList("r0", "r1", "r2", "r3");
- private static final Map<String, Set<Bundle>> regionBundles = new HashMap<String, Set<Bundle>>();
-
@Before
public void setUp() throws Exception {
long nextId = 0;
@@ -121,7 +118,7 @@ public class StandardRegionDigraphPeristenceTests {
for (Region region : digraph) {
tails.add(region);
}
- // create multiple connections between each region
+ // create multiple connections between each region with cycles
for (Region head : digraph) {
for (Region tail : tails) {
if (head == tail)
@@ -134,12 +131,26 @@ public class StandardRegionDigraphPeristenceTests {
}
private void doTest() throws IOException, InvalidSyntaxException, BundleException {
- ByteArrayOutputStream memOut = new ByteArrayOutputStream();
- StandardRegionDigraphPersistence.writeRegionDigraph(new DataOutputStream(memOut), digraph);
+ // test a single write
+ doTest(1);
+ // test writing and reading the digraph multiple times to same stream
+ doTest(10);
+ }
- ByteArrayInputStream memIn = new ByteArrayInputStream(memOut.toByteArray());
- RegionDigraph copy = StandardRegionDigraphPersistence.readRegionDigraph(new DataInputStream(memIn), systemBundleContext, threadLocal);
- assertEquals(digraph, copy);
+ private void doTest(int iterations) throws IOException, InvalidSyntaxException, BundleException {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ DataOutputStream dataOut = new DataOutputStream(output);
+ for (int i = 0; i < iterations; i++) {
+ StandardRegionDigraphPersistence.writeRegionDigraph(new DataOutputStream(output), digraph);
+ }
+ dataOut.close();
+
+ DataInputStream dataIn = new DataInputStream(new ByteArrayInputStream(output.toByteArray()));
+ for (int i = 0; i < iterations; i++) {
+ RegionDigraph copy = StandardRegionDigraphPersistence.readRegionDigraph(dataIn, systemBundleContext, threadLocal);
+ assertEquals(digraph, copy);
+ }
+ dataIn.close();
}
private RegionFilter createFilter(String... input) throws InvalidSyntaxException {