From 6e5f5e15ad5d2a3ea3ec2289137d52e71b049967 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Sat, 10 Mar 2007 21:34:53 +0000 Subject: [PATCH] Refactored to introduce constants for number of ops and number of threads for tuning. --- .../context/SecurityContextHolderTests.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/src/test/java/org/acegisecurity/context/SecurityContextHolderTests.java b/core/src/test/java/org/acegisecurity/context/SecurityContextHolderTests.java index 8178d998c5..c069c385e0 100644 --- a/core/src/test/java/org/acegisecurity/context/SecurityContextHolderTests.java +++ b/core/src/test/java/org/acegisecurity/context/SecurityContextHolderTests.java @@ -34,6 +34,9 @@ public class SecurityContextHolderTests extends TestCase { private static int errors = 0; + private static final int NUM_OPS = 25; + private static final int NUM_THREADS = 10; + //~ Constructors =================================================================================================== public SecurityContextHolderTests() { @@ -134,7 +137,7 @@ public class SecurityContextHolderTests extends TestCase { final Random rnd = new Random(); Thread t = new Thread(new Runnable() { - public void run() { + public void run() { if (injectAuthIntoCurrentThread) { // Set authentication in this thread SecurityContextHolder.getContext() @@ -147,7 +150,7 @@ public class SecurityContextHolderTests extends TestCase { } // Do some operations in current thread, checking authentication is as expected in the current thread (ie another thread doesn't change it) - for (int i = 0; i < 25; i++) { + for (int i = 0; i < NUM_OPS; i++) { String currentUsername = (SecurityContextHolder.getContext().getAuthentication() == null) ? null : SecurityContextHolder.getContext().getAuthentication().getName(); @@ -242,14 +245,14 @@ public class SecurityContextHolderTests extends TestCase { SecurityContextHolder.setStrategyName(InheritableThreadLocalSecurityContextHolderStrategy.class.getName()); assertTrue(new SecurityContextHolder().toString() .lastIndexOf("SecurityContextHolder[strategy='org.acegisecurity.context.InheritableThreadLocalSecurityContextHolderStrategy'") != -1); - loadStartAndWaitForThreads(true, "Main_", 10, false, true); + loadStartAndWaitForThreads(true, "Main_", NUM_THREADS, false, true); assertEquals("Thread errors detected; review log output for details", 0, errors); } public void testSynchronizationGlobal() throws Exception { SecurityContextHolder.clearContext(); SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL); - loadStartAndWaitForThreads(true, "Main_", 10, true, false); + loadStartAndWaitForThreads(true, "Main_", NUM_THREADS, true, false); assertEquals("Thread errors detected; review log output for details", 0, errors); } @@ -257,14 +260,14 @@ public class SecurityContextHolderTests extends TestCase { throws Exception { SecurityContextHolder.clearContext(); SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL); - loadStartAndWaitForThreads(true, "Main_", 10, false, true); + loadStartAndWaitForThreads(true, "Main_", NUM_THREADS, false, true); assertEquals("Thread errors detected; review log output for details", 0, errors); } public void testSynchronizationThreadLocal() throws Exception { SecurityContextHolder.clearContext(); SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_THREADLOCAL); - loadStartAndWaitForThreads(true, "Main_", 10, false, false); + loadStartAndWaitForThreads(true, "Main_", NUM_THREADS, false, false); assertEquals("Thread errors detected; review log output for details", 0, errors); } }