Skip to content

Commit

Permalink
Migrate tests to JUnit5
Browse files Browse the repository at this point in the history
* use JUnit5 annotations
* use JUnit5 Assertions and Assumptions
* remove public visibility from tests
* remove junit-vintage-engine dependency
  • Loading branch information
strangelookingnerd committed Nov 13, 2024
1 parent d87bda1 commit 67acab0
Show file tree
Hide file tree
Showing 142 changed files with 2,686 additions and 3,273 deletions.
13 changes: 4 additions & 9 deletions commons-jcs3-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>

<!-- Exclude for now -->
<!-- dependency>
Expand Down Expand Up @@ -171,7 +166,7 @@
<java.security.manager>true</java.security.manager>
<java.security.policy>${basedir}/src/test/conf/cache.policy</java.security.policy>
<java.util.logging.config.file>${basedir}/src/test/test-conf/logging.properties</java.util.logging.config.file>
</systemPropertyVariables>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
Expand All @@ -189,7 +184,7 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>testWithLog4j2</id>
Expand All @@ -216,7 +211,7 @@
<systemPropertyVariables>
<jcs.logSystem>log4j2</jcs.logSystem>
<log4j.configurationFile>src/test/test-conf/log4j2-test.xml</log4j.configurationFile>
</systemPropertyVariables>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -249,7 +244,7 @@
<java.security.manager>true</java.security.manager>
<java.security.policy>${basedir}/src/test/conf/cache.policy</java.security.policy>
<java.util.logging.config.file>${basedir}/src/test/test-conf/logging.properties</java.util.logging.config.file>
</systemPropertyVariables>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package org.apache.commons.jcs3;

import junit.extensions.ActiveTestSuite;
import junit.framework.Test;
import junit.framework.TestCase;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -23,115 +19,78 @@
* under the License.
*/

import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;

/**
* Test which exercises the hierarchical removal when the cache is active.
*/
public class ConcurrentRemovalLoadTest
@Execution(ExecutionMode.CONCURRENT)
class ConcurrentRemovalLoadTest
{
/**
* A unit test suite for JUnit. This verifies that we can remove hierarchically while the region
* is active.
* @return The test suite
*/
public static Test suite()
{
final ActiveTestSuite suite = new ActiveTestSuite();

suite.addTest(new TestCase("testRemoveCache1" )
{
@Override
public void runTest()
throws Exception
{
RemovalTestUtil.runTestPutThenRemoveCategorical( 0, 200 );
}
});
@BeforeEach
void setUp()
{
JCS.setConfigFilename( "/TestRemoval.ccf" );
}

suite.addTest(new TestCase("testPutCache1" )
{
@Override
public void runTest()
throws Exception
{
RemovalTestUtil.runPutInRange( 300, 400 );
}
});
@Test
void testRemoveCache1_FirstRange()
throws Exception
{
RemovalTestUtil.runTestPutThenRemoveCategorical( 0, 200 );
}

suite.addTest(new TestCase("testPutCache2" )
{
@Override
public void runTest()
throws Exception
{
RemovalTestUtil.runPutInRange( 401, 600 );
}
});
@Test
void testPutCache1()
throws Exception
{
RemovalTestUtil.runPutInRange( 300, 400 );
}

// stomp on previous put
suite.addTest(new TestCase("testPutCache3" )
{
@Override
public void runTest()
throws Exception
{
RemovalTestUtil.runPutInRange( 401, 600 );
}
});
@Test
void testPutCache2_FirstRange()
throws Exception
{
RemovalTestUtil.runPutInRange( 401, 600 );
}

suite.addTest(new TestCase("testRemoveCache1" )
{
@Override
public void runTest()
throws Exception
{
RemovalTestUtil.runTestPutThenRemoveCategorical( 601, 700 );
}
});
@Test
void testPutCache3_StompPreviousPut()
throws Exception
{
RemovalTestUtil.runPutInRange( 401, 600 );
}

suite.addTest(new TestCase("testRemoveCache1" )
{
@Override
public void runTest()
throws Exception
{
RemovalTestUtil.runTestPutThenRemoveCategorical( 701, 800 );
}
});
@Test
void testRemoveCache1_SecondRange()
throws Exception
{
RemovalTestUtil.runTestPutThenRemoveCategorical( 601, 700 );
}

suite.addTest(new TestCase("testRemoveCache1" )
{
@Override
public void runTest()
throws Exception
{
RemovalTestUtil.runTestPutThenRemoveCategorical( 901, 1000 );
}
});
@Test
void testRemoveCache1_ThirdRange()
throws Exception
{
RemovalTestUtil.runTestPutThenRemoveCategorical( 701, 800 );
}

suite.addTest(new TestCase("testPutCache2" )
{
// verify that there are no errors with concurrent gets.
@Override
public void runTest()
throws Exception
{
RemovalTestUtil.runGetInRange( 0, 1000, false );
}
});
return suite;
@Test
void testRemoveCache1_FourthRange()
throws Exception
{
RemovalTestUtil.runTestPutThenRemoveCategorical( 901, 1000 );
}

/**
* Test setup
* <p>
* @throws Exception
*/
@Before
public void setUp()
@Test
void testPutCache2_WithConcurrentGets()
throws Exception
{
JCS.setConfigFilename( "/TestRemoval.ccf" );
// verify that there are no errors with concurrent gets
RemovalTestUtil.runGetInRange( 0, 1000, false );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
* under the License.
*/

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.apache.commons.jcs3.access.CacheAccess;
import org.apache.commons.jcs3.engine.behavior.ICacheElement;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
*/
public class JCSCacheElementRetrievalUnitTest
class JCSCacheElementRetrievalUnitTest
{
/**
*
* @throws Exception
*/
@Test
public void testSimpleElementRetrieval()
void testSimpleElementRetrieval()
throws Exception
{
final CacheAccess<String, String> jcs = JCS.getInstance( "testCache1" );
Expand All @@ -44,10 +44,10 @@ public void testSimpleElementRetrieval()

final long now = System.currentTimeMillis();
final ICacheElement<String, String> elem = jcs.getCacheElement( "test_key" );
assertEquals( "Name wasn't right", "testCache1", elem.getCacheName() );
assertEquals( "testCache1", elem.getCacheName(), "Name wasn't right" );

final long diff = now - elem.getElementAttributes().getCreateTime();
assertTrue( "Create time should have been at or after the call", diff >= 0 );
assertTrue( diff >= 0, "Create time should have been at or after the call" );

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.apache.commons.jcs3;

import static org.junit.Assert.assertEquals;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -21,20 +19,23 @@
* under the License.
*/

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.jcs3.access.GroupCacheAccess;
import org.apache.commons.jcs3.access.exception.CacheException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Test Case for JCS-73, modeled after the Groovy code by Alexander Kleymenov
*/
public class JCSConcurrentCacheAccessUnitTest{
class JCSConcurrentCacheAccessUnitTest
{
/**
* Worker thread
*/
Expand Down Expand Up @@ -131,29 +132,30 @@ public void run()
*/
protected List<String> valueMismatchList;

@Before
public void setUp() throws Exception
@BeforeEach
void setUp()
throws Exception
{
JCS.setConfigFilename( "/TestJCS-73.ccf" );
cache = JCS.getGroupCacheInstance( "cache" );
errcount = new AtomicInteger();
valueMismatchList = new CopyOnWriteArrayList<>();
}

@After
public void tearDown()
@AfterEach
void tearDown()
throws Exception
{
cache.clear();
cache.dispose();
}

/**
/**
*
* @throws Exception
*/
@Test
public void testConcurrentAccess()
void testConcurrentAccess()
throws Exception
{
final Worker[] worker = new Worker[THREADS];
Expand All @@ -169,12 +171,12 @@ public void testConcurrentAccess()
worker[i].join();
}

assertEquals("Error count should be 0", 0, errcount.intValue());
assertEquals( 0, errcount.intValue(), "Error count should be 0" );
for (final String msg : valueMismatchList)
{
System.out.println(msg);
}
assertEquals("Value mismatch count should be 0", 0, valueMismatchList.size());
assertEquals( 0, valueMismatchList.size(), "Value mismatch count should be 0" );
}

}
Loading

0 comments on commit 67acab0

Please sign in to comment.