pass unit test
org.opentest4j.AssertionFailedError: expected:
at org.apache.dubbo.common.extension.AdaptiveClassCodeGeneratorTest.testGenerate(AdaptiveClassCodeGeneratorTest.java:45)
the souce of is AdaptiveClassCodeGeneratorTest
public class AdaptiveClassCodeGeneratorTest {
@Test
public void testGenerate() throws IOException {
AdaptiveClassCodeGenerator generator = new AdaptiveClassCodeGenerator(HasAdaptiveExt.class, "adaptive");
String value = generator.generate();
URL url = getClass().getResource("/org/apache/dubbo/common/extension/adaptive/HasAdaptiveExt$Adaptive");
try (InputStream inputStream = url.openStream()) {
String content = IOUtils.read(new InputStreamReader(inputStream, "UTF-8"));
assertTrue(content.contains(value));
}
}
}
When I add the following code to it, the unit pass.
value = value.replace("\r","");
value = value.replace("\n","");
content = content.replace("\r","");
content = content.replace("\n","");
Currently we are using travis CI which base on linux, it maybe have some issue for windows platform.
Does Dubbo have plan to make unit-test adaptation on windows platform? (or maybe I can make a little contribute on it)
i think unit-test can running in windows platform is very necessary. it can help developer who work on windows platform more easily to verify features.
i think unit-test can running in windows platform is very necessary. it can help developer who work on windows platform more easily to verify features.
yeah. I agree. I have some ideas at this moment.
We are using travis ci, it has window platform support(Only Windows Server, version 1809 is currently supported), special os will lead more waiting time when running CI. we need a trade off.
For your question at this moment. @AlbumenJ I have some suggestions:
replace. it may confuse people.Also, I'm not sure if this is only unit test issue in windows platform or there are some function issue in windows platform too. I don't have a PC which running Windows so I can't confirm this
@htynkn junit5 have the feature which can only run test on linux with the @EnableOnOs annotations. but I think both adaptation windows and unix in this test case is better nad not hard.
In these days, I try to make unit-test running on Windows platform correctly and I found there are several problems:
ConditionalEventListenerTest.testOnEvent added OnlyHelloWorldEventListener and EventDispatcherTest.testDefaultMethods requires empty lisitener )EnumBak.testNormal )ExplicitCallbackTest ), the provider is unable to get the method, which is Null ( line 288 ) , when DubboInvokerAvilableTest using ProtocolUtils to export somethings. ( Howerver both ExplicitCallbackTest and DubboInvokerAvilableTest can run correctly separately )For CodeGenerator, I think it is inevitable to adapt separately for Windows and Linux platform which have quite different way to manage line speration.
In source code of AdaptiveClassCodeGenerator, it is really use '\n' only.
package org.apache.dubbo.common.extension;
/**
* Code generator for Adaptive class
*/
public class AdaptiveClassCodeGenerator {
private static final String CODE_METHOD_DECLARATION = "public %s %s(%s) %s {\n%s}\n";
...
/**
* generate method declaration
*/
private String generateMethod(Method method) {
String methodReturnType = method.getReturnType().getCanonicalName();
String methodName = method.getName();
String methodContent = generateMethodContent(method);
String methodArgs = generateMethodArguments(method);
String methodThrows = generateMethodThrows(method);
return String.format(CODE_METHOD_DECLARATION, methodReturnType, methodName, methodArgs, methodThrows, methodContent);
}
}
However, when reading files from filesystem on Windows, the result always contains '\r'.
So, I try to fix it and leave a comment by the following way.
public class AdaptiveClassCodeGeneratorTest {
@Test
public void testGenerate() throws IOException {
AdaptiveClassCodeGenerator generator = new AdaptiveClassCodeGenerator(HasAdaptiveExt.class, "adaptive");
String value = generator.generate();
URL url = getClass().getResource("/org/apache/dubbo/common/extension/adaptive/HasAdaptiveExt$Adaptive");
try (InputStream inputStream = url.openStream()) {
String content = IOUtils.read(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
// Content getting from resource in Windows platform contains '\r' delimiter
content = content.replaceAll("\r","");
assertTrue(content.contains(value));
}
}
}
Also, I think it is feasible to compile generator's result in runtime and compare it to resource from source.
@AlbumenJ you can create a PR to fix this testcase issue
close via #5913
Thanks for @AlbumenJ 's great work
Most helpful comment
In these days, I try to make unit-test running on Windows platform correctly and I found there are several problems:
ConditionalEventListenerTest.testOnEventaddedOnlyHelloWorldEventListenerandEventDispatcherTest.testDefaultMethodsrequires empty lisitener )EnumBak.testNormal)ExplicitCallbackTest), the provider is unable to get the method, which is Null ( line 288 ) , whenDubboInvokerAvilableTestusing ProtocolUtils to export somethings. ( Howerver bothExplicitCallbackTestandDubboInvokerAvilableTestcan run correctly separately )For CodeGenerator, I think it is inevitable to adapt separately for Windows and Linux platform which have quite different way to manage line speration.
In source code of
AdaptiveClassCodeGenerator, it is really use '\n' only.However, when reading files from filesystem on Windows, the result always contains '\r'.
So, I try to fix it and leave a comment by the following way.
Also, I think it is feasible to compile generator's result in runtime and compare it to resource from source.