comparison test/org/dancres/blitz/SpaceWriteTakeTest.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.disk.Disk;
9 import org.dancres.blitz.disk.DiskTxn;
10
11 public class SpaceWriteTakeTest {
12 public static void main(String args[]) {
13
14 try {
15 System.out.println("Start space");
16
17 SpaceImpl mySpace = new SpaceImpl(null);
18
19 System.out.println("Prepare entry");
20
21 EntryMangler myMangler = new EntryMangler();
22
23 System.out.println("init'd entry");
24 MangledEntry myPackedEntry =
25 myMangler.mangle(new TestEntry().init());
26
27 System.out.println("Do write: " +
28 mySpace.write(myPackedEntry, null,
29 Lease.FOREVER));
30
31 MangledEntry myWild = myMangler.mangle(new TestEntry());
32 System.out.println("Do wild read: ");
33 System.out.println(mySpace.read(myWild, null, Lease.FOREVER));
34
35 System.out.println("Do specific take:");
36 System.out.println(mySpace.take(myPackedEntry, null,
37 Lease.FOREVER));
38
39 myPackedEntry = myMangler.mangle(new TestEntry().init2());
40
41 System.out.println("Do write: " +
42 mySpace.write(myPackedEntry, null,
43 Lease.FOREVER));
44
45 myPackedEntry = myMangler.mangle(new TestEntry().init2());
46 System.out.println("Do other take: ");
47 System.out.println(mySpace.take(myPackedEntry, null,
48 Lease.FOREVER));
49
50 myPackedEntry = myMangler.mangle(new TestEntry().init3());
51 System.out.println("Do non-match take: ");
52 System.out.println(mySpace.take(myPackedEntry, null,
53 5000));
54
55 // This is naughty - we're messing with internals directly
56 // but it's a useful test
57 //
58 System.out.println("Do sync write: " +
59 mySpace.write(myPackedEntry, null,
60 Lease.FOREVER));
61
62 System.out.println("Force sync");
63 Disk.sync();
64
65 System.out.println("Do wild take");
66 System.out.println(mySpace.take(myWild, null, Lease.FOREVER));
67
68 System.out.println("Do stop");
69
70 mySpace.stop();
71
72 } catch (Exception anE) {
73 System.err.println("Got exception :(");
74 anE.printStackTrace(System.err);
75 }
76
77 }
78
79 public static class TestEntry implements Entry {
80 public String rhubarb;
81 public Integer count;
82
83 public TestEntry() {
84 }
85
86 public TestEntry init() {
87 rhubarb = "blah";
88 count = new Integer(5);
89
90 return this;
91 }
92
93 public TestEntry init2() {
94 rhubarb = "blahblah";
95 count = new Integer(5);
96
97 return this;
98 }
99
100 public TestEntry init3() {
101 rhubarb = "blahh";
102 count = new Integer(5);
103
104 return this;
105 }
106
107 public String toString() {
108 return super.toString() + ", " + rhubarb + ", " + count;
109 }
110 }
111 }