awips2/edexOsgi/com.raytheon.edex.common/unit-test/com/raytheon/edex/test/TestLockManagerClustered.java
Matt Nash 82300ccdcf Moving 12.1.1 into ss_sync
Former-commit-id: 580e2938d7 [formerly 66be3bec40] [formerly c83e5ff474 [formerly 2a9569942c48542cf708b6c0b9189146fd954c11]]
Former-commit-id: c83e5ff474
Former-commit-id: 1faae42484
2012-01-19 11:53:12 -06:00

123 lines
3.5 KiB
Java

/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.edex.test;
import java.io.File;
import java.lang.Thread.State;
import com.raytheon.uf.common.datastorage.locking.ClusteredLockManager;
import com.raytheon.uf.common.datastorage.locking.LockException;
/**
* Clustered version of TestLockManager. This requires multicast.
*
* Run two copies of this program at the same time.
*
* Should yield approximately 0.5 on each program.
*
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 20, 2007 chammack Initial Creation.
*
* </pre>
*
* @author chammack
* @version 1
*/
public class TestLockManagerClustered {
public static void main(String[] args) {
try {
// ClusteredLockManager lockMgr =
// ClusteredLockManager.getInstance();
ClusteredLockManager.getInstance();
Thread.sleep(2000);
} catch (LockException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// Test #1 Clustered
System.out
.println("Clustered test: Programs should both return approximately 0.5 load");
LockTester lt1 = new LockTester(1);
Thread thread1 = new Thread(lt1);
thread1.start();
System.out.println("Running test: This will take a few seconds...");
while (thread1.getState() != State.TERMINATED) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.exit(0);
}
public static class LockTester implements Runnable {
private int id;
public LockTester(int id) {
this.id = id;
}
public void run() {
try {
ClusteredLockManager lockMgr = ClusteredLockManager
.getInstance();
int hits = 0;
for (int i = 0; i < 1000; i++) {
boolean gotLock = lockMgr.getLock(new File("/tmp/foo"),
true);
Thread.sleep(10);
if (gotLock) {
lockMgr.releaseLock(new File("/tmp/foo"));
hits++;
}
Thread.sleep(10);
}
System.out.println("Thread #" + id + ":: " + (hits) / 1000.0);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}