Author: peter_firmstone Date: Sat Feb 23 11:37:22 2013 New Revision: 1449297
URL: http://svn.apache.org/r1449297 Log: Attempt to fix last failing test UseNotifyLeaseTestRenew on arm Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/leasing/LeaseGrantTestBase.java river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/leasing/LeaseUsesTestBase.java river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/leasing/UseNotifyLeaseTest.java Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/leasing/LeaseGrantTestBase.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/leasing/LeaseGrantTestBase.java?rev=1449297&r1=1449296&r2=1449297&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/leasing/LeaseGrantTestBase.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/leasing/LeaseGrantTestBase.java Sat Feb 23 11:37:22 2013 @@ -45,12 +45,12 @@ public abstract class LeaseGrantTestBase * If true then the tests expects leases to granted * exactly. If false the grant can be for less than the request */ - private boolean exact = false; + private volatile boolean exact = false; /** * The length of time the lease should be asked for */ - protected long durationRequest; + protected volatile long durationRequest; /** * The expiration time that would be given for the duration request @@ -58,32 +58,32 @@ public abstract class LeaseGrantTestBase * <code>Lease.ANY</code>. * @see #resourceRequested */ - protected long expirationRequest; + private volatile long expirationRequest; /** * The local time just after the request. <code>expirationRequest</code> * is <code>requestStart + durationRequest</code>. * @see #resourceRequested */ - protected long requestStart; + private volatile long requestStart; /** * The length of time that leases get cliped to if they are too * long. A negative value indicates no cliping is expected */ - protected long clip = -1; + private volatile long clip = -1; /* * Acceptable slop interval between when we think lease will * expire and when it acctually does. */ - protected long slop = 2000; + protected volatile long slop = 2000; /** * Test the passed lease to see if it has been granted for an * acceptable length of time */ - protected boolean isAcceptable(Lease underTest) { + protected final synchronized boolean isAcceptable(Lease underTest) { // if we asked for ANY lease, then any duration is cool if (durationRequest == Lease.ANY) { @@ -130,7 +130,7 @@ public abstract class LeaseGrantTestBase * Return <code>true</code> if the <code>duration</code> is within * the allowed slop range relative to the given <code>value</code>. */ - protected boolean withinSlop(long duration, long value) { + protected final synchronized boolean withinSlop(long duration, long value) { return (duration > value - slop && duration < value + slop); } @@ -138,12 +138,12 @@ public abstract class LeaseGrantTestBase * Log a requested lease and its result, for the given type of lease. */ protected void logRequest(String type, Lease lease) { - logger.log(Level.INFO, "Lease " + type + ": " + lease); - logger.log(Level.INFO, "\treq:" + expirationRequest); - logger.log(Level.INFO, "\tgot:" + lease.getExpiration()); - logger.log(Level.INFO, "\taprox duration:" + (lease.getExpiration() - - requestStart)); - logger.log(Level.INFO, "\tdrift:" + (lease.getExpiration() - expirationRequest)); + logger.log(Level.INFO, "Lease {0}: {1}", new Object[]{type, lease}); + logger.log(Level.INFO, "\treq:{0}", expirationRequest); + logger.log(Level.INFO, "\tgot:{0}", lease.getExpiration()); + logger.log(Level.INFO, "\taprox duration:{0}", (lease.getExpiration() - + requestStart)); + logger.log(Level.INFO, "\tdrift:{0}", (lease.getExpiration() - expirationRequest)); } /** @@ -153,7 +153,7 @@ public abstract class LeaseGrantTestBase * @see #requestStart * @see #expirationRequest */ - protected void resourceRequested() { + protected final synchronized void resourceRequested() { requestStart = System.currentTimeMillis(); expirationRequest = requestStart + durationRequest; @@ -219,10 +219,10 @@ public abstract class LeaseGrantTestBase } // Log out test options. - logger.log(Level.INFO, "exact = " + exact); - logger.log(Level.INFO, "clip = " + clip); - logger.log(Level.INFO, "slop = " + slop); - logger.log(Level.INFO, "durationRequest = " + durationRequest); + logger.log(Level.INFO, "exact = {0}", exact); + logger.log(Level.INFO, "clip = {0}", clip); + logger.log(Level.INFO, "slop = {0}", slop); + logger.log(Level.INFO, "durationRequest = {0}", durationRequest); } /** Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/leasing/LeaseUsesTestBase.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/leasing/LeaseUsesTestBase.java?rev=1449297&r1=1449296&r2=1449297&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/leasing/LeaseUsesTestBase.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/leasing/LeaseUsesTestBase.java Sat Feb 23 11:37:22 2013 @@ -32,6 +32,7 @@ import com.sun.jini.qa.harness.QAConfig; // Shared classes import com.sun.jini.qa.harness.Test; import com.sun.jini.test.share.TestBase; +import java.util.concurrent.atomic.AtomicLong; /** @@ -45,22 +46,22 @@ public abstract class LeaseUsesTestBase /** * Lease being used */ - protected Lease lease = null; + private volatile Lease lease = null; // Time lease will expire - private long expTime; + private volatile long expTime; // Time lease of lease duration - private long durTime; + private volatile long durTime; // How long until the lease should be renewed - private long renewTime; + private volatile long renewTime; // What to set renewTime to, if < 0 the half of duration - private long renewWait; + private volatile long renewWait; // Time to let cancel to propgate - private long cancelSlop; + private volatile long cancelSlop; // Set renew and exp times private void setTimes() { @@ -74,15 +75,17 @@ public abstract class LeaseUsesTestBase renewTime = renewWait + curTime; } } - private long renewals = 0; - private boolean cancel; - private long shutdownTime = -1; - private long restartSleep = 10000; + private final AtomicLong renewals = new AtomicLong(); + private volatile boolean cancel; + private volatile long shutdownTime = -1; + private volatile long restartSleep = 10000; /** * Method should acquire some resource under a lease and return * the Lease. Note the returned value will be stored in * the <code>lease</code> field + * @return Lease + * @throws TestException * @see LeaseUsesTestBase#lease */ protected abstract Lease acquireResource() throws TestException; @@ -92,6 +95,8 @@ public abstract class LeaseUsesTestBase * acquireResource() is still available, returning * <code>true</code> if is and <code>false</code> if it is not. * If some other exception occurs the method should call fail + * @return true if still available + * @throws TestException */ protected abstract boolean isAvailable() throws TestException; @@ -118,12 +123,13 @@ public abstract class LeaseUsesTestBase * availability, most tests should not use this option. Defaults to * 0. * </DL> + * @throws Exception */ protected void parse() throws Exception { super.parse(); // Get values from property file for this test. - renewals = getConfig().getIntConfigVal("com.sun.jini.test.share.renew", 0); + renewals.set(getConfig().getIntConfigVal("com.sun.jini.test.share.renew", 0)); cancel = getConfig().getBooleanConfigVal("com.sun.jini.test.share.cancel", false); renewWait = getConfig().getLongConfigVal("com.sun.jini.test.share.renew_wait", -1); shutdownTime = getConfig().getLongConfigVal("com.sun.jini.test.share.shutdownTime", -1); @@ -131,12 +137,12 @@ public abstract class LeaseUsesTestBase cancelSlop = getConfig().getLongConfigVal("com.sun.jini.test.share.cancel_slop", 0); // Log out test options. - logger.log(Level.INFO, "renewals = " + renewals); - logger.log(Level.INFO, "cancel = " + cancel); - logger.log(Level.INFO, "renewWait = " + renewWait); - logger.log(Level.INFO, "shutdownTime = " + shutdownTime); - logger.log(Level.INFO, "restartSleep = " + restartSleep); - logger.log(Level.INFO, "cancelSlop = " + cancelSlop); + logger.log(Level.INFO, "renewals = {0}", renewals); + logger.log(Level.INFO, "cancel = {0}", cancel); + logger.log(Level.INFO, "renewWait = {0}", renewWait); + logger.log(Level.INFO, "shutdownTime = {0}", shutdownTime); + logger.log(Level.INFO, "restartSleep = {0}", restartSleep); + logger.log(Level.INFO, "cancelSlop = {0}", cancelSlop); } public void run() throws Exception { @@ -155,10 +161,10 @@ public abstract class LeaseUsesTestBase throw new TestException("Lease had an improper duration"); } - if (cancel && renewals <= 0) { + if (cancel && renewals.get() <= 0) { cancel(); } else { - logger.log(Level.INFO, "Expire Test: Slop = " + slop); + logger.log(Level.INFO, "Expire Test: Slop = {0}", slop); while (true) { @@ -185,42 +191,43 @@ public abstract class LeaseUsesTestBase */ final long preTime = System.currentTimeMillis(); final boolean stillThere; + final long postTime; + synchronized (this){ + stillThere = isAvailable(); - stillThere = isAvailable(); - - /* - * We also use postTime as an approximation of the - * current time for the remainder of this iteration - */ - final long postTime = System.currentTimeMillis(); + /* + * We also use postTime as an approximation of the + * current time for the remainder of this iteration + */ + postTime = System.currentTimeMillis(); - /* - * Check for late expiration against preTime - * postTime - slop elemnates overflow problems when - * expTime == FOREVER - */ - if (stillThere && (preTime - slop > expTime)) { - throw new TestException( - "Resource was available after lease expiration"); - } + /* + * Check for late expiration against preTime + * postTime - slop elemnates overflow problems when + * expTime == FOREVER + */ + if (stillThere && (preTime - slop > expTime)) { + throw new TestException( + "Resource was available after lease expiration"); + } - // Check for early expiration against postTime - logger.log(Level.FINEST, - "postTime: " + postTime - + ", (expTime - slop): " + (expTime - slop)); - if (!stillThere && (postTime < expTime - slop)) { - throw new TestException( - "Resource was not available before lease expiration"); - } + // Check for early expiration against postTime + logger.log(Level.FINEST, "postTime: {0}, (expTime - slop): {1}", + new Object[]{postTime, expTime - slop}); + if (!stillThere && (postTime < expTime - slop)) { + throw new TestException( + "Resource was not available before lease expiration"); + } - if (!stillThere) { + if (!stillThere) { - // No use testing once it is gone - break; + // No use testing once it is gone + break; + } } // Do we need to renew - if (renewals > 0 && postTime > renewTime) { + if (renewals.get() > 0 && postTime > renewTime) { lease.renew(durationRequest); resourceRequested(); setTimes(); @@ -230,8 +237,8 @@ public abstract class LeaseUsesTestBase throw new TestException( "Renewed lease had an improper duration"); } - renewals--; - } else if (renewals == 0 && cancel) { + renewals.decrementAndGet(); + } else if (renewals.get() == 0 && cancel) { cancel(); /* @@ -270,8 +277,8 @@ public abstract class LeaseUsesTestBase */ if (cancelSlop > 0) { logger.log(Level.INFO, - "Sleeping for " + cancelSlop + " milliseconds to " - + "allow cancel to propagate..."); + "Sleeping for {0}" + " milliseconds to " + + "allow cancel to propagate...", cancelSlop); Thread.sleep(cancelSlop); logger.log(Level.INFO, "awake"); } Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/leasing/UseNotifyLeaseTest.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/leasing/UseNotifyLeaseTest.java?rev=1449297&r1=1449296&r2=1449297&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/leasing/UseNotifyLeaseTest.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/leasing/UseNotifyLeaseTest.java Sat Feb 23 11:37:22 2013 @@ -35,16 +35,17 @@ import com.sun.jini.qa.harness.TestExcep // Shared classes import com.sun.jini.test.share.TestBase; import com.sun.jini.test.share.UninterestingEntry; +import java.util.concurrent.atomic.AtomicInteger; /** * Tests binding between leases and notifications in JavaSpaces */ public class UseNotifyLeaseTest extends LeaseUsesTestBase { final private Entry aEntry = new UninterestingEntry(); - private LeasedSpaceListener listener; - private JavaSpace space; - private long callbackWait; - private boolean verbose; + private volatile LeasedSpaceListener listener; + private volatile JavaSpace space; + private volatile long callbackWait; + private volatile boolean verbose; /** * Parse our args @@ -79,6 +80,8 @@ public class UseNotifyLeaseTest extends try { listener = new LeasedSpaceListener(getConfig().getConfiguration()); space = (JavaSpace) services[0]; + JavaSpace space = this.space; + LeasedSpaceListener listener = this.listener; EventRegistration reg = space.notify(aEntry, null, listener, durationRequest, null); reg = (EventRegistration) @@ -94,14 +97,16 @@ public class UseNotifyLeaseTest extends } return lease; } - private int count = 0; + private final AtomicInteger count = new AtomicInteger(); protected boolean isAvailable() throws TestException { boolean bReturn = false; try { - logger.log(Level.FINEST, "Writing entry " + ++count); - synchronized (listener) { + logger.log(Level.FINEST, "Writing entry {0}", count.getAndIncrement()); + LeasedSpaceListener listener = this.listener; + JavaSpace space = this.space; + synchronized (listener) { // Can't synchronize on volatile field. listener.received = false; /* @@ -110,12 +115,9 @@ public class UseNotifyLeaseTest extends * listener.received transtion from false->true */ addOutriggerLease(space.write(aEntry, null, Lease.ANY), false); - logger.log(Level.FINEST, - "Waiting for listener to be called at " - + (new java.util.Date())); + logger.log(Level.FINEST, "Waiting for listener to be called at {0}", (new java.util.Date())); listener.wait(callbackWait); - logger.log(Level.FINEST, - "Wait done at " + (new java.util.Date()) + ", received = " + listener.received); + logger.log(Level.FINEST, "Wait done at {0}, received = {1}", new Object[]{new java.util.Date(), listener.received}); bReturn = listener.received; } } catch (Exception e) {
