Author: mladen.turk(a)jboss.com
Date: 2007-10-29 04:02:45 -0400 (Mon, 29 Oct 2007)
New Revision: 1147
Added:
trunk/sight/test/org/jboss/sight/MutexTest.java
Modified:
trunk/sight/test/org/jboss/sight/DirectoryTest.java
trunk/sight/test/org/jboss/sight/ShmTest.java
Log:
Tune up Test suite
Modified: trunk/sight/test/org/jboss/sight/DirectoryTest.java
===================================================================
--- trunk/sight/test/org/jboss/sight/DirectoryTest.java 2007-10-29 08:02:20 UTC (rev
1146)
+++ trunk/sight/test/org/jboss/sight/DirectoryTest.java 2007-10-29 08:02:45 UTC (rev
1147)
@@ -60,6 +60,18 @@
assertEquals(Error.APR_SUCCESS, rc);
rc = Directory.makeRecursive("bar/foo", FileProtection.OS_DEFAULT);
assertEquals(Error.APR_SUCCESS, rc);
+
+ FileInfo fi;
+ Directory dir = new Directory("bar");
+ DirectoryIterator di = dir.getContent(EnumSet.of(FileInfoFlags.DIRENT));
+ fi = di.next();
+ assertEquals(".", fi.BaseName);
+ fi = di.next();
+ assertEquals("..", fi.BaseName);
+ fi = di.next();
+ assertEquals("foo", fi.BaseName);
+ dir.close();
+
rc = Directory.remove("bar/foo");
assertEquals(Error.APR_SUCCESS, rc);
rc = Directory.remove("bar");
Added: trunk/sight/test/org/jboss/sight/MutexTest.java
===================================================================
--- trunk/sight/test/org/jboss/sight/MutexTest.java (rev 0)
+++ trunk/sight/test/org/jboss/sight/MutexTest.java 2007-10-29 08:02:45 UTC (rev 1147)
@@ -0,0 +1,104 @@
+/*
+ * SIGHT - System information gathering hybrid tool
+ *
+ * Copyright(c) 2007 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+package org.jboss.sight;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Process Mutext Test.
+ *
+ */
+public class MutexTest extends TestCase
+{
+
+ int counter = 0;
+
+ public static void main(String[] args)
+ {
+ junit.textui.TestRunner.run(MutexTest.class);
+ }
+
+ protected void setUp()
+ throws Exception
+ {
+ Library.initialize("");
+ }
+
+ protected void tearDown()
+ throws Exception
+ {
+ Library.shutdown();
+ }
+
+ class MutexTestClient extends Thread
+ {
+ Mutex m;
+
+ MutexTestClient()
+ throws Exception
+ {
+ m = new Mutex("./ProcessMutex.lock", MutexType.DEFAULT);
+ }
+
+ public void run() {
+ /* First one should be locked */
+ int rv = m.tryLock();
+
+ assertTrue(Status.APR_STATUS_IS_EBUSY(rv));
+ try {
+ rv = m.lock();
+ assertEquals(0, counter);
+ assertEquals(Error.APR_SUCCESS, rv);
+ rv = m.unlock();
+ assertEquals(Error.APR_SUCCESS, rv);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+ public void testMutex()
+ throws Exception
+ {
+ Mutex m = new Mutex("./ProcessMutex.lock", MutexType.DEFAULT);
+
+ m.lock();
+ new MutexTestClient().start();
+ /* Settle up */
+ Thread.sleep(1000);
+ m.unlock();
+ for (; counter < 10; counter++) {
+ m.lock();
+ Thread.sleep(10);
+ m.unlock();
+ }
+ assertNotNull(m.getName());
+
+ m.destroy();
+ }
+
+}
Property changes on: trunk/sight/test/org/jboss/sight/MutexTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/sight/test/org/jboss/sight/ShmTest.java
===================================================================
--- trunk/sight/test/org/jboss/sight/ShmTest.java 2007-10-29 08:02:20 UTC (rev 1146)
+++ trunk/sight/test/org/jboss/sight/ShmTest.java 2007-10-29 08:02:45 UTC (rev 1147)
@@ -43,7 +43,7 @@
protected void setUp()
throws Exception
{
- Library.initialize(null);
+ Library.initialize("");
}
protected void tearDown()
@@ -52,28 +52,27 @@
Library.shutdown();
}
- public void testShmCreate()
+ public void testShm()
throws Exception
{
int size = 64 * 1024;
- Shm shm = new Shm("C:\\TEMP\\SharedMemory.bin", size);
- ByteBuffer bb = shm.getBytes();
-
+ Shm shmc = new Shm("./SharedMemory.bin", size);
+ ByteBuffer bb = shmc.getBytes();
+
assertEquals(size, bb.capacity());
bb.putInt(0xCAFEBABE);
bb.putInt(0xDEADBEEF);
- }
- public void testShmOpen()
- throws Exception
- {
- int size = 64 * 1024;
- Shm shm = new Shm("C:\\TEMP\\SharedMemory.bin", size);
- ByteBuffer bb = shm.getBytes();
-
- assertEquals(size, bb.capacity());
- assertEquals(0xCAFEBABE, bb.getInt());
- assertEquals(0xDEADBEEF, bb.getInt());
+ /* Attach Shared memory */
+ Shm shma = new Shm();
+
+ int rv = shma.attach("./SharedMemory.bin");
+ assertEquals(rv, Error.APR_SUCCESS);
+ assertEquals(size, shma.size());
+
+ ByteBuffer br = shma.getBytes();
+ assertEquals(0xCAFEBABE, br.getInt());
+ assertEquals(0xDEADBEEF, br.getInt());
}
}
Show replies by date