ICE 3.4.2
[php5-ice-freebsdport.git] / java / test / IceUtil / fileLock / ClientFail.java
blob7b51828cba84e7fae7a9a1e9bd4440ac7ba3f30f
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4 //
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
7 //
8 // **********************************************************************
10 package test.IceUtil.fileLock;
12 import java.io.BufferedReader;
13 import java.io.InputStreamReader;
15 import java.io.File;
16 import java.io.RandomAccessFile;
17 import java.io.EOFException;
18 import java.io.UTFDataFormatException;
19 import java.io.IOException;
22 public class ClientFail
24 private static void
25 test(boolean b)
27 if(!b)
29 throw new RuntimeException();
33 public static void
34 main(String[] argvs)
36 IceUtilInternal.FileLock lock = null;
37 try
39 lock = new IceUtilInternal.FileLock("file.lock");
40 test(false);
42 catch(IceUtil.FileLockException ex)
44 System.out.println("File lock not acquired.");
46 // Try to read the pid of the lock owner from the lock file, in Windows
47 // we don't write pid to lock files.
49 if(!System.getProperty("os.name").startsWith("Windows"))
51 String pid = "";
52 try
54 RandomAccessFile file = new RandomAccessFile(new File("file.lock"), "r");
55 pid = file.readUTF();
57 catch(EOFException eofEx)
59 System.out.println("exception:\n" + eofEx.toString());
60 test(false);
62 catch(UTFDataFormatException utfEx)
64 System.out.println("exception:\n" + utfEx.toString());
65 test(false);
67 catch(IOException ioEx)
69 System.out.println("exception:\n" + ioEx.toString());
70 test(false);
73 if(pid.length() == 0)
75 test(false);
77 System.out.println("Lock owned by: " + pid);