labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
Subject svn commit: r763655 - in /labs/magma/trunk/foundation-basics/src: main/java/org/apache/magma/basics/startup/Cycle.java test/java/org/apache/magma/basics/startup/ test/java/org/apache/magma/basics/startup/CycleTest.java
Date Thu, 09 Apr 2009 13:57:55 GMT
Author: simoneg
Date: Thu Apr  9 13:57:54 2009
New Revision: 763655

URL: http://svn.apache.org/viewvc?rev=763655&view=rev
Log:
LABS-338 : Additional tests and more garbage collection ease for Cycle

Added:
    labs/magma/trunk/foundation-basics/src/test/java/org/apache/magma/basics/startup/
    labs/magma/trunk/foundation-basics/src/test/java/org/apache/magma/basics/startup/CycleTest.java
Modified:
    labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup/Cycle.java

Modified: labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup/Cycle.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup/Cycle.java?rev=763655&r1=763654&r2=763655&view=diff
==============================================================================
--- labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup/Cycle.java
(original)
+++ labs/magma/trunk/foundation-basics/src/main/java/org/apache/magma/basics/startup/Cycle.java
Thu Apr  9 13:57:54 2009
@@ -190,6 +190,14 @@
 		}
 	}
 	
+	/**
+	 * Cleans the local variables. This should not be needed, cause the cycle instance itself
should go
+	 * to garbage, but is here just to avoid blocking garbage collection in case someone is
holding a
+	 * reference to the cycle.
+	 */
+	protected void teardownLocalVariables() {
+		this.localVars.clear();
+	}
 	
 	
 	

Added: labs/magma/trunk/foundation-basics/src/test/java/org/apache/magma/basics/startup/CycleTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-basics/src/test/java/org/apache/magma/basics/startup/CycleTest.java?rev=763655&view=auto
==============================================================================
--- labs/magma/trunk/foundation-basics/src/test/java/org/apache/magma/basics/startup/CycleTest.java
(added)
+++ labs/magma/trunk/foundation-basics/src/test/java/org/apache/magma/basics/startup/CycleTest.java
Thu Apr  9 13:57:54 2009
@@ -0,0 +1,65 @@
+package org.apache.magma.basics.startup;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+
+public class CycleTest {
+
+	@Test
+	public void startStop() throws Exception {
+		Cycle.start();
+		Cycle cycle1 = Cycle.get();
+		Cycle.start();
+		Cycle cycle2 = Cycle.get();
+		assertSame(cycle1, cycle2);
+		Cycle cycle3 = Cycle.get();
+		assertSame(cycle2, cycle3);
+		Cycle.stop();
+		Cycle.start();
+		Cycle cycle4 = Cycle.get();
+		assertNotSame(cycle2, cycle4);
+		assertNotSame(cycle1, cycle4);
+	}
+	
+	@Test
+	public void localVars() throws Exception {
+		Cycle.start();
+		Cycle cycle1 = Cycle.get();
+		cycle1.setLocalVar("test", "test");
+		assertEquals("test", cycle1.getLocalVar("test"));
+		Cycle.stop();
+		assertNull(cycle1.getLocalVar("test"));
+	}
+	
+	@Test
+	public void cycleThreadLocal() throws Exception {
+		Cycle.start();
+		CycleThreadLocal<String> ctl = new CycleThreadLocal<String>();
+		ctl.set("test");
+		assertEquals("test", ctl.get());
+		ctl.remove();
+		assertNull(ctl.get());
+		ctl.set("test");
+		assertEquals("test", ctl.get());
+		Cycle.stop();
+		assertNull(ctl.get());
+	}
+	
+	@Test
+	public void cleanableTest() throws Exception {
+		final boolean[] cleaned = new boolean[1];
+		Cycle.start();
+		Cycle cycle1 = Cycle.get();
+		cycle1.register(new CycleCleanable() {
+			public void remove() {
+				cleaned[0] = true;
+			}
+		});
+		assertFalse(cleaned[0]);
+		Cycle.stop();
+		assertTrue(cleaned[0]);
+	}
+	
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message