1 21 package com.db4o.test; 22 23 import com.db4o.ext.*; 24 import com.db4o.foundation.*; 25 26 public class SetSemaphore { 27 28 public void test() { 29 30 final ExtObjectContainer client1 = Test.objectContainer(); 31 32 Test.ensure(client1.setSemaphore("hi", 0)); 33 Test.ensure(client1.setSemaphore("hi", 0)); 34 35 if (Test.clientServer) { 36 final ExtObjectContainer client2 = Test.open(); 37 final ExtObjectContainer client3 = Test.open(); 38 final ExtObjectContainer client4 = Test.open(); 39 final ExtObjectContainer client5 = Test.open(); 40 41 Test.ensure(!client2.setSemaphore("hi", 0)); 42 client1.releaseSemaphore("hi"); 43 Test.ensure(client2.setSemaphore("hi", 50)); 44 Test.ensure(!client1.setSemaphore("hi", 0)); 45 Test.ensure(!client3.setSemaphore("hi", 0)); 46 47 new GetAndRelease(client3); 48 new GetAndRelease(client2); 49 new GetAndRelease(client1); 50 new GetAndRelease(client4); 51 new GetAndRelease(client5); 52 53 Cool.sleepIgnoringInterruption(1000); 54 Test.ensure(client1.setSemaphore("hi", 0)); 55 client1.close(); 56 57 new GetAndRelease(client3); 58 new GetAndRelease(client2); 59 Cool.sleepIgnoringInterruption(1000); 60 61 client2.close(); 62 client3.close(); client4.close(); 65 client5.setSemaphore("hi", 1000); 66 } 67 68 } 69 70 static class GetAndRelease implements Runnable { 71 72 ExtObjectContainer client; 73 74 public GetAndRelease(ExtObjectContainer client) { 75 this.client = client; 76 new Thread (this).start(); 77 } 78 79 public void run() { 80 long time = System.currentTimeMillis(); 81 Test.ensure(client.setSemaphore("hi", 50000)); 82 time = System.currentTimeMillis() - time; 83 Cool.sleepIgnoringInterruption(50); 85 86 client.releaseSemaphore("hi"); 88 } 89 } 90 91 } 92 | Popular Tags |