comparison test/org/dancres/blitz/LeaseTrackTest.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 java.io.Serializable;
4 import java.rmi.MarshalledObject;
5
6 import net.jini.core.entry.Entry;
7 import net.jini.core.lease.Lease;
8
9 import org.dancres.blitz.mangler.*;
10
11 import org.dancres.blitz.lease.SpaceUID;
12
13 import org.dancres.blitz.disk.Disk;
14
15 public class LeaseTrackTest {
16 /**
17 Write 3 entries, saving leases
18
19 sync
20
21 Update entry 0 lease
22
23 sync
24
25 Cancel entry 0 lease
26
27 sync
28
29 stop
30 */
31 public static void main(String args[]) {
32 try {
33 System.out.println("Start space");
34
35 SpaceImpl mySpace = new SpaceImpl(null);
36
37 System.out.println("Prepare entry");
38
39 EntryMangler myMangler = new EntryMangler();
40 TestEntry myEntry = new TestEntry();
41 myEntry.init();
42
43 System.out.println("init'd entry");
44 MangledEntry myPackedEntry = myMangler.mangle(new TestEntry());
45
46 System.out.println("Do write");
47 SpaceUID[] myUIDs = new SpaceUID[3];
48
49 for (int i = 0; i < 3; i++ ) {
50 myUIDs[i] = mySpace.write(myPackedEntry, null, 50000).getUID();
51 }
52
53 Disk.sync();
54
55 System.out.println("Renew entry");
56 mySpace.getLeaseControl().renew(myUIDs[0], 500000);
57
58 Disk.sync();
59 System.out.println("Cancel entry");
60 mySpace.getLeaseControl().cancel(myUIDs[0]);
61
62 Disk.sync();
63 System.out.println("Settling");
64
65 try {
66 Thread.sleep(5000);
67 } catch (InterruptedException anIE) {
68 }
69
70 System.out.println("Do stop");
71
72 mySpace.stop();
73
74 } catch (Exception anE) {
75 System.err.println("Got exception :(");
76 anE.printStackTrace(System.err);
77 }
78 }
79
80 public static class TestEntry implements Entry {
81 public String rhubarb;
82 public Integer count;
83
84 public TestEntry() {
85 }
86
87 public void init() {
88 rhubarb = "blah";
89 count = new Integer(5);
90 }
91
92 public String toString() {
93 return super.toString() + ", " + rhubarb + ", " + count;
94 }
95 }
96 }