Hi Folks, Registry unit tests depends on the order of test methods. This order is the order of method declarations in a test class. Following is a sample class. If the tests methods are executed in the following declared order, then everything works fine. This was the behavior in Java 6. Junit retrieves the list of test methods using Java reflection and in Java 6 returned list of method are in the declared order.
CustomQueryTest extends BaseTestCase { + *testAssociationsQuery*(); + *testAssociationsCollectionQuery*() ; + *testQueryAsParameter*(); + *testCustomQueryResultsOrderForComments*(); + *testCustomQueryResultsOrderForResources*(); } But in Java 8, reflections API behavior has been changed it seems. Order of the list of methods of a class changes time to time. Because of this behavior in Java 8, there are test failures in Registry.core module. Senaka and myself arrive at this conclusion at the same time it seems :) We've got multiple options to solve this problem. 1) Fix the inter-dependency issues of registry.core unit tests. This will take a bit of time and if we do this, we won't be able to release Carbon 4.4.0 on time. *2)* Migration to JUnit 4.*. This was released sometime back and we should have moved to this or TestNG. in JUnit 4.*, they are introduced annotation based test declaration like TestNG. Therefore we can change the failing test classes in the following manner. - Rename test methods with numbers to that we can sort them in ascending order - User the class level annotation called @FixMethodOrder to specify the test method execution order. @FixMethodOrder(*MethodSorters.NAME_ASCENDING*) CustomQueryTest extends BaseTestCase { @Test + *test1AssociationsQuery*(); @Test + *test2**AssociationsCollectionQuery*() ; @Test + *test3**QueryAsParameter*(); @Test + *test4**CustomQueryResultsOrderForComments*(); @Test + *test5**CustomQueryResultsOrderForResources*(); } Once this change is done is few test classes, registry.core unit tests are passing. I've attached a sample diff file as well. If there are no objections from the Registry team, I will go ahead and follow this method as a workaround. I've already created a Jira to fix this properly. https://wso2.org/jira/browse/CARBON-15183 Thanks, Sameera. ---------- Forwarded message ---------- From: Senaka Fernando <sen...@wso2.com> Date: Wed, Feb 25, 2015 at 1:37 AM Subject: Re: test failues To: Sameera Jayasoma <same...@wso2.com> Hi Sameera, Going by your findings I did some research. So, the cause of this can be this, [1]. The reflection APIs have been improved in JDK 8, which could explain the reason why JUnit sees the order of the methods in a different way. IINM the registry test ordering was fixed roughly when we first started running on JDK 6, and so it must have stayed good until the new JDK. But, this can also mean few other things. Reflection is also used in components and dependencies like Axis2, which can be broken in some ways. Best to keep an eye. WRT JUnit 4, on a separate note, IMHO, we should have been running that for sometime now, it was released ages back right? [1] http://docs.oracle.com/javase/8/docs/technotes/guides/reflection/enhancements.html Thanks, Senaka. On Tue, Feb 24, 2015 at 7:59 PM, Senaka Fernando <sen...@wso2.com> wrote: > Ah ok, :). We came into the same conclusion then :). No objections, the > registry team can look into this. > > Thanks, > Senaka. > > On Tue, Feb 24, 2015 at 7:56 PM, Sameera Jayasoma <same...@wso2.com> > wrote: > >> Looks like after migrating to Junit 4* and using the following method >> order works fine. >> >> @FixMethodOrder(MethodSorters.NAME_ASCENDING) >> >> >> Any objections for this temporary solution until registry team fix the >> test failures >> >> On Tue, Feb 24, 2015 at 11:58 PM, Sameera Jayasoma <same...@wso2.com> >> wrote: >> >>> >>> >>> -- >>> Sameera Jayasoma, >>> Software Architect, >>> >>> WSO2, Inc. (http://wso2.com) >>> email: same...@wso2.com >>> blog: http://blog.sameera.org >>> twitter: https://twitter.com/sameerajayasoma >>> flickr: http://www.flickr.com/photos/sameera-jayasoma/collections >>> Mobile: 0094776364456 >>> >>> Lean . Enterprise . Middleware >>> >>> >> >> >> -- >> Sameera Jayasoma, >> Software Architect, >> >> WSO2, Inc. (http://wso2.com) >> email: same...@wso2.com >> blog: http://blog.sameera.org >> twitter: https://twitter.com/sameerajayasoma >> flickr: http://www.flickr.com/photos/sameera-jayasoma/collections >> Mobile: 0094776364456 >> >> Lean . Enterprise . Middleware >> >> > > > -- > > > *[image: http://wso2.com] <http://wso2.com>Senaka Fernando* > Solutions Architect; WSO2 Inc.; http://wso2.com > > > > *Member; Apache Software Foundation; http://apache.org > <http://apache.org>E-mail: senaka AT wso2.com <http://wso2.com>**P: +1 > 408 754 7388 <%2B1%20408%20754%207388>; ext: 51736*; > > > *M: +44 782 741 1966 <%2B44%20782%20741%201966>Linked-In: > http://linkedin.com/in/senakafernando > <http://linkedin.com/in/senakafernando>*Lean . Enterprise . Middleware > -- *[image: http://wso2.com] <http://wso2.com>Senaka Fernando* Solutions Architect; WSO2 Inc.; http://wso2.com *Member; Apache Software Foundation; http://apache.org <http://apache.org>E-mail: senaka AT wso2.com <http://wso2.com>**P: +1 408 754 7388 <%2B1%20408%20754%207388>; ext: 51736*; *M: +44 782 741 1966 <%2B44%20782%20741%201966>Linked-In: http://linkedin.com/in/senakafernando <http://linkedin.com/in/senakafernando>*Lean . Enterprise . Middleware -- Sameera Jayasoma, Software Architect, WSO2, Inc. (http://wso2.com) email: same...@wso2.com blog: http://blog.sameera.org twitter: https://twitter.com/sameerajayasoma flickr: http://www.flickr.com/photos/sameera-jayasoma/collections Mobile: 0094776364456 Lean . Enterprise . Middleware
diff --git a/core/org.wso2.carbon.registry.core/src/test/java/org/wso2/carbon/registry/core/test/jdbc/JDBCRegistryTest.java b/core/org.wso2.carbon.registry.core/src/test/java/org/wso2/carbon/registry/core/test/jdbc/JDBCRegistryTest.java index e303e43..efad899 100644 --- a/core/org.wso2.carbon.registry.core/src/test/java/org/wso2/carbon/registry/core/test/jdbc/JDBCRegistryTest.java +++ b/core/org.wso2.carbon.registry.core/src/test/java/org/wso2/carbon/registry/core/test/jdbc/JDBCRegistryTest.java @@ -16,6 +16,9 @@ package org.wso2.carbon.registry.core.test.jdbc; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; import org.wso2.carbon.registry.core.Collection; import org.wso2.carbon.registry.core.*; import org.wso2.carbon.registry.core.exceptions.RegistryException; @@ -29,6 +32,7 @@ import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.util.*; +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class JDBCRegistryTest extends BaseTestCase { /** @@ -59,7 +63,8 @@ public class JDBCRegistryTest extends BaseTestCase { } } - public void testIllegalCharacters() throws Exception { + @Test + public void test1IllegalCharacters() throws Exception { Resource r1 = registry.newResource(); String str = "My Content"; r1.setContentStream(new ByteArrayInputStream(str.getBytes())); @@ -76,7 +81,8 @@ public class JDBCRegistryTest extends BaseTestCase { } } - public void testMediaTypesInCaps() throws Exception { + @Test + public void test2MediaTypesInCaps() throws Exception { MediaTypesUtils.getResourceMediaTypeMappings( embeddedRegistryService.getConfigSystemRegistry()); Resource r1 = registry.newResource(); @@ -87,7 +93,8 @@ public class JDBCRegistryTest extends BaseTestCase { assertEquals("image/jpeg", registry.get("/abc.JPG").getMediaType()); } - public void testCollectionDetails() throws Exception { + @Test + public void test3CollectionDetails() throws Exception { Resource r1 = registry.newResource(); String str = "My Content"; r1.setContentStream(new ByteArrayInputStream(str.getBytes())); @@ -110,7 +117,8 @@ public class JDBCRegistryTest extends BaseTestCase { r1.discard(); } - public void testFlatResourceHandling() throws RegistryException { + @Test + public void test4FlatResourceHandling() throws RegistryException { Resource r1 = registry.newResource(); r1.setDescription("This is a test resource used for registry testing."); String r1Content = "<c>This is r1 content</c>"; @@ -143,7 +151,8 @@ public class JDBCRegistryTest extends BaseTestCase { r1f.discard(); } - public void testHierarchicalResourceHandling() throws Exception { + @Test + public void test5HierarchicalResourceHandling() throws Exception { // add a resource @@ -194,7 +203,8 @@ public class JDBCRegistryTest extends BaseTestCase { assertTrue("Deleted collection /d1/r1 is not marked as deleted.", f2); } - public void testResourceVersioning() throws Exception { + @Test + public void test6ResourceVersioning() throws Exception { boolean isVersionOnChange = registry.getRegistryContext().isVersionOnChange(); Resource r1 = registry.newResource(); byte[] r1Content = "R1 content".getBytes(); @@ -256,7 +266,8 @@ public class JDBCRegistryTest extends BaseTestCase { } // todo: test this with persistence db - public void testPutOnSamePath() { + @Test + public void test7PutOnSamePath() { try { Resource userProfile = registry.newResource(); @@ -275,7 +286,8 @@ public class JDBCRegistryTest extends BaseTestCase { } } - public void testCollectionVersioning() throws Exception { + @Test + public void test8CollectionVersioning() throws Exception { String r1Content = "r1 content1"; Resource r1 = registry.newResource(); @@ -319,8 +331,8 @@ public class JDBCRegistryTest extends BaseTestCase { !containsString(restoredC10Children, "/c10/r2")); } - - public void testValueChange() throws Exception { + @Test + public void test9ValueChange() throws Exception { Resource r1 = registry.newResource(); String content1 = "Content1"; r1.setContent(content1.getBytes()); @@ -336,7 +348,8 @@ public class JDBCRegistryTest extends BaseTestCase { } - public void testComments() throws Exception { + @Test + public void test10Comments() throws Exception { // add a resource Resource r1 = registry.newResource(); byte[] r1content = "R1 content".getBytes(); @@ -379,7 +392,7 @@ public class JDBCRegistryTest extends BaseTestCase { registry.delete("/d12"); } - public void testRatings() throws Exception { + public void test11Ratings() throws Exception { // add a resource Resource r1 = registry.newResource(); byte[] r1content = "R1 content".getBytes(); @@ -395,7 +408,8 @@ public class JDBCRegistryTest extends BaseTestCase { registry.delete("/d13"); } - public void testUserDefinedResourceQuery() throws Exception { + @Test + public void test12UserDefinedResourceQuery() throws Exception { Resource r1 = registry.newResource(); String r1Content = "this is r1 content"; r1.setContent(r1Content.getBytes()); @@ -442,7 +456,8 @@ public class JDBCRegistryTest extends BaseTestCase { assertTrue("Path /c2/r2 should be in the results.", matchingPaths.contains("/c2/r2")); } - public void testUserDefinedRatingsQuery() throws Exception { + @Test + public void test13UserDefinedRatingsQuery() throws Exception { Resource r1 = registry.newResource(); String r1Content = "this is r1 content"; r1.setContent(r1Content.getBytes()); @@ -495,7 +510,8 @@ public class JDBCRegistryTest extends BaseTestCase { // rating2.getContent().toString(), "4"); } - public void testUserDefinedTagsQuery() throws Exception { + @Test + public void test14UserDefinedTagsQuery() throws Exception { Resource r1 = registry.newResource(); String r1Content = "this is r1 content"; r1.setContent(r1Content.getBytes()); @@ -550,7 +566,8 @@ public class JDBCRegistryTest extends BaseTestCase { (String)tag1.getContent(), "jsp"); } - public void testUserDefinedCommentsQuery() throws Exception { + @Test + public void test15UserDefinedCommentsQuery() throws Exception { Resource r1 = registry.newResource(); String r1Content = "this is r1 content"; r1.setContent(r1Content.getBytes()); @@ -611,7 +628,8 @@ public class JDBCRegistryTest extends BaseTestCase { (String)c2.getContent(), "replace this with a better one"); } - public void testTagsAsResources() { + @Test + public void test16TagsAsResources() { //Resource r1 = new Resource(); //String r1Content = "this is r1 content"; //r1.setContent(r1Content.getBytes()); @@ -664,7 +682,8 @@ public class JDBCRegistryTest extends BaseTestCase { //int a = 1; } - public void testCommentsAsResources() throws RegistryException { + @Test + public void test17CommentsAsResources() throws RegistryException { Resource r1 = registry.newResource(); String r1Content = "this is r1 content"; r1.setContent(r1Content.getBytes()); @@ -715,7 +734,8 @@ public class JDBCRegistryTest extends BaseTestCase { commentStrings.contains("simple test resource.")); } - public void testRatingsAsResources() throws RegistryException { + @Test + public void test18RatingsAsResources() throws RegistryException { Resource r5 = registry.newResource(); String r5Content = "this is r5 content"; r5.setContent(r5Content.getBytes()); @@ -761,7 +781,8 @@ public class JDBCRegistryTest extends BaseTestCase { assertEquals("Ratings are not retrieved properly as resources.", rating, 3); } - public void testLogs() throws RegistryException { + @Test + public void test19Logs() throws RegistryException { String r1Content = "this is the r200 content."; Resource r1 = registry.newResource(); r1.setContent(r1Content.getBytes()); @@ -776,7 +797,8 @@ public class JDBCRegistryTest extends BaseTestCase { } - public void testResourceDelete() throws RegistryException { + @Test + public void test20ResourceDelete() throws RegistryException { String content1 = "Content1"; Resource r1 = registry.newResource(); r1.setContent(content1); @@ -827,7 +849,8 @@ public class JDBCRegistryTest extends BaseTestCase { } - public void testCombinedScenario() throws RegistryException { + @Test + public void test21CombinedScenario() throws RegistryException { // put a content resource in to the root String r1Content = "this is the r1 content."; Resource r1 = registry.newResource(); @@ -905,7 +928,8 @@ public class JDBCRegistryTest extends BaseTestCase { registry.delete("/c2"); } - public void testGetMetaData() throws RegistryException { + @Test + public void test22GetMetaData() throws RegistryException { String r1Content = "this is the rgm content."; Resource r = registry.newResource(); @@ -920,7 +944,8 @@ public class JDBCRegistryTest extends BaseTestCase { } - public void testResourceCollectionMix() throws RegistryException { + @Test + public void test23ResourceCollectionMix() throws RegistryException { Resource defaultGadgetCollection = registry.newResource(); registry.put("/system/gadgets", defaultGadgetCollection); @@ -949,8 +974,8 @@ public class JDBCRegistryTest extends BaseTestCase { assertTrue("R should exist", registry.resourceExists("/system/gadgets")); } - - public void testLastUpdateWithGet() throws RegistryException { + @Test + public void test24LastUpdateWithGet() throws RegistryException { Resource r1 = registry.newResource(); r1.setContent("test"); registry.put("/pqr/xyz", r1); @@ -970,9 +995,8 @@ public class JDBCRegistryTest extends BaseTestCase { assertEquals("update time should be equal", date2, date3); } - - - public void testLastUpdateWithPut() throws RegistryException { + @Test + public void test25LastUpdateWithPut() throws RegistryException { Resource r1 = registry.newResource(); registry.put("/pqr/xyz", r1);
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev