comparison test/org/dancres/blitz/SpaceBlockTest.java @ 0:3dc0c5604566

Initial checkin of blitz 2.0 fcs - no installer yet.
author Dan Creswell <dan.creswell@gmail.com>
date Sat, 21 Mar 2009 11:00:06 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3dc0c5604566
1 package org.dancres.blitz;
2
3 import net.jini.core.entry.Entry;
4 import net.jini.core.lease.Lease;
5
6 import org.dancres.blitz.mangler.*;
7
8 import org.dancres.blitz.entry.EntryRepositoryFactory;
9
10 import org.dancres.blitz.disk.DiskTxn;
11
12 public class SpaceBlockTest implements Runnable {
13 private SpaceImpl theSpace;
14
15 private SpaceBlockTest() {
16 }
17
18 public void run() {
19 try {
20 System.out.println("Prepare template");
21
22 EntryMangler myMangler = new EntryMangler();
23 MangledEntry myPackedTemplate =
24 myMangler.mangle(new TestEntry().init());
25
26 System.out.println("Taking....." + Thread.currentThread());
27 MangledEntry myResult = theSpace.take(myPackedTemplate, null,
28 20000);
29
30 if (myResult != null)
31 System.out.println(myMangler.unMangle(myResult) + " " + Thread.currentThread());
32 else
33 System.out.println("No entry found :(" + Thread.currentThread());
34
35 } catch (Exception anException) {
36 System.out.println("Taker failed");
37 anException.printStackTrace(System.out);
38 }
39 }
40
41 public void test() {
42 try {
43 System.out.println("Start space");
44
45 theSpace = new SpaceImpl(null);
46
47 System.out.println("Prepare entry");
48 EntryMangler myMangler = new EntryMangler();
49 MangledEntry myPackedEntry =
50 myMangler.mangle(new TestEntry().init());
51
52 System.out.println("Start taker");
53 Thread myThread = new Thread(this);
54 myThread.start();
55
56 System.out.println("Start taker");
57 myThread = new Thread(this);
58 myThread.start();
59
60 try {
61 Thread.sleep(5000);
62 } catch (InterruptedException anIE) {
63 }
64
65 System.out.println("Do write: " +
66 theSpace.write(myPackedEntry, null,
67 Lease.FOREVER) +
68 Thread.currentThread());
69
70 try {
71 Thread.sleep(5000);
72 } catch (InterruptedException anIE) {
73 }
74
75 System.out.println("Do write: " +
76 theSpace.write(myPackedEntry, null,
77 Lease.FOREVER) +
78 Thread.currentThread());
79
80 try {
81 Thread.sleep(5000);
82 } catch (InterruptedException anIE) {
83 }
84
85 theSpace.stop();
86
87 } catch (Exception anE) {
88 System.err.println("Writer failed :(");
89 anE.printStackTrace(System.err);
90 }
91 }
92
93 public static void main(String args[]) {
94 new SpaceBlockTest().test();
95 }
96
97 public static class TestEntry implements Entry {
98 public String rhubarb;
99 public Integer count;
100
101 public TestEntry() {
102 }
103
104 public TestEntry init() {
105 rhubarb = "blah";
106 count = new Integer(5);
107
108 return this;
109 }
110
111 public TestEntry init2() {
112 rhubarb = "blahblah";
113 count = new Integer(5);
114
115 return this;
116 }
117
118 public TestEntry init3() {
119 rhubarb = "blahh";
120 count = new Integer(5);
121
122 return this;
123 }
124
125 public String toString() {
126 return super.toString() + ", " + rhubarb + ", " + count;
127 }
128 }
129 }