Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from junit4 to junit5 #692

Merged
merged 4 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<azure.functions.java.core.library.version>1.2.0</azure.functions.java.core.library.version>
<azure.functions.java.spi>1.0.0</azure.functions.java.spi>
<azure.functions.java.library.version>2.2.0</azure.functions.java.library.version>
<jupiter.version>5.9.1</jupiter.version>
<mockito-core.version>4.11.0</mockito-core.version>
</properties>
<licenses>
<license>
Expand Down Expand Up @@ -67,12 +69,6 @@
<artifactId>azure-functions-java-spi</artifactId>
<version>${azure.functions.java.spi}</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-library</artifactId>
<version>${azure.functions.java.library.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
Expand Down Expand Up @@ -114,15 +110,21 @@
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-library</artifactId>
<version>${azure.functions.java.library.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.6.1</version>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito-core.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import java.util.*;
import java.util.logging.Level;

import com.microsoft.azure.functions.worker.Util;
import com.microsoft.azure.functions.worker.WorkerLogManager;
import com.microsoft.azure.functions.worker.broker.*;
import com.microsoft.azure.functions.worker.description.*;
import com.microsoft.azure.functions.rpc.messages.*;


public class FunctionLoadRequestHandler extends MessageHandler<FunctionLoadRequest, FunctionLoadResponse.Builder> {
public FunctionLoadRequestHandler(JavaFunctionBroker broker) {
super(StreamingMessage::getFunctionLoadRequest,
Expand All @@ -20,7 +22,7 @@ public FunctionLoadRequestHandler(JavaFunctionBroker broker) {

@Override
String execute(FunctionLoadRequest request, FunctionLoadResponse.Builder response) throws Exception {
WorkerLogManager.getSystemLogger().log(Level.INFO, "FunctionLoadRequest received by the Java worker");
WorkerLogManager.getSystemLogger().log(Level.INFO, "FunctionLoadRequest received by the Java worker, Java version - " + Util.getJavaVersion());
final RpcFunctionMetadata metadata = request.getMetadata();
final FunctionMethodDescriptor descriptor = createFunctionDescriptor(request.getFunctionId(), metadata);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import com.microsoft.azure.functions.worker.broker.*;
import com.microsoft.azure.functions.rpc.messages.*;

import static com.microsoft.azure.functions.worker.Util.getJavaVersion;

public class InvocationRequestHandler extends MessageHandler<InvocationRequest, InvocationResponse.Builder> {
public InvocationRequestHandler(JavaFunctionBroker broker) {
super(StreamingMessage::getInvocationRequest,
Expand All @@ -25,7 +23,6 @@ public InvocationRequestHandler(JavaFunctionBroker broker) {

@Override
String execute(InvocationRequest request, InvocationResponse.Builder response) throws Exception {
WorkerLogManager.getSystemLogger().log(Level.INFO, "Java version - " + getJavaVersion());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this log is removed? This was added to make it easier to get java version in kusto logs specifically for consumption apps as they use placeholders. I suggest we retain this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can check the version by using log here

WorkerLogManager.getSystemLogger().info("Loading JavaMethodExecutorImpl");
, and from applens we can also tell the version.

My concern is that put it in invocation is not a good place, when cx is having thousands rps, this can be kind of annoying and it may impact the throughput and performance when the rps is high as we need to run getJavaverion very frequently and log them to host from stdout.

So if we have a way to tell the java version, let's just save the resources as much as possible.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understand your concern. I feel it is better to retain it with a lower log level. This log specifically informs not only the java version but also the java path which is useful for the customer and us. Some customers had reached out asking how to get this information. The time we would save with one log is quite miniscule. Feel free to combine java version with the next log if it saves time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the log to function load request handler as function load is far fewer than function invocation.

WorkerLogManager.getSystemLogger().log(Level.INFO, "InvocationRequest received by the Java worker");
final String functionId = request.getFunctionId();
final String invocationId = request.getInvocationId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ public void addWorkerUrl(URL url) throws IOException {
addUrlToSystemClassLoader(url);
}

public static boolean isUrlPointingToAFile(URL url) throws UnsupportedEncodingException {
String decodedPath = URLDecoder.decode(url.getPath(), "UTF-8");
File file = new File(decodedPath);
return file.exists();
}

private void addUrlToSystemClassLoader(URL url) throws IOException {
URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class<?> sysclass = URLClassLoader.class;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.microsoft.azure.functions.worker;

import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;

public class UtilTests {
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class UtilTest {

@Test
public void isTrueNull() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.microsoft.azure.functions.worker.binding.tests;

import static org.junit.Assert.assertEquals;

import java.lang.invoke.WrongMethodTypeException;
import java.util.Optional;

import org.apache.commons.lang3.ArrayUtils;
import org.junit.Test;

import com.google.protobuf.ByteString;
import com.microsoft.azure.functions.worker.binding.BindingData;
import com.microsoft.azure.functions.worker.binding.RpcByteArrayDataSource;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class RpcByteArrayDataSourceTests {
public class RpcByteArrayDataSourceTest {

@Test
public void rpcByteArrayDataSource_To_byteArray() {
Expand All @@ -26,7 +26,7 @@ public void rpcByteArrayDataSource_To_byteArray() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
byte[] actualBytes = (byte[]) actualArg.getValue();
String actualString = new String(actualBytes);
assertEquals(actualString, expectedString);
assertEquals(expectedString, actualString);
}

@Test
Expand All @@ -41,7 +41,7 @@ public void rpcByteArrayDataSource_To_ByteArray() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
Byte[] actualBytes = (Byte[]) actualArg.getValue();
String actualString = new String(ArrayUtils.toPrimitive(actualBytes));
assertEquals(actualString, expectedString);
assertEquals(expectedString, actualString);
}

@Test
Expand All @@ -58,7 +58,7 @@ public void rpcByteArrayDataSource_To_POJO() {
TestBlobData.class);
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
TestBlobData actualBlobData = (TestBlobData) actualArg.getValue();
assertEquals(actualBlobData.blobText, testBlobData.blobText);
assertEquals(testBlobData.blobText, actualBlobData.blobText);
}

@Test
Expand All @@ -73,7 +73,7 @@ public void rpcByteArrayDataSource_To_String() {
String.class);
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
String actualBlobData = (String) actualArg.getValue();
assertEquals(actualBlobData, expectedString);
assertEquals(expectedString, actualBlobData);
}

public static class TestBlobData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.reflect.TypeUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.lang.invoke.WrongMethodTypeException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

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

public class RpcCollectionByteArrayDataSourceTest {
@Test
Expand All @@ -41,7 +39,7 @@ public void rpcByteArrayDataSource_To_byte_Array() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
byte[][] actualBytes = (byte[][]) actualArg.getValue();
String actualString = new String(actualBytes[0]);
assertEquals(actualString, expectedString);
assertEquals(expectedString, actualString);
}

@Test
Expand All @@ -65,7 +63,7 @@ public void rpcByteArrayDataSource_To_Byte_Array() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
Byte[][] actualBytes = (Byte[][]) actualArg.getValue();
String actualString = new String(ArrayUtils.toPrimitive(actualBytes[0]));
assertEquals(actualString, expectedString);
assertEquals(expectedString, actualString);
}

@Test
Expand All @@ -89,7 +87,7 @@ public void rpcByteArrayDataSource_default_To_List_byte() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
List<byte[]> actualBytes = (List) actualArg.getValue();
String actualString = new String(actualBytes.get(0));
assertEquals(actualString, expectedString);
assertEquals(expectedString, actualString);
}

@Test
Expand All @@ -113,7 +111,7 @@ public void rpcByteArrayDataSource_To_List_byte() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
List<byte[]> actualBytes = (List) actualArg.getValue();
String actualString = new String(actualBytes.get(0));
assertEquals(actualString, expectedString);
assertEquals(expectedString, actualString);
}

@Test
Expand All @@ -137,7 +135,7 @@ public void rpcByteArrayDataSource_To_List_Byte() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
List<Byte[]> actualBytes = (List) actualArg.getValue();
String actualString = new String(ArrayUtils.toPrimitive(actualBytes.get(0)));
assertEquals(actualString, expectedString);
assertEquals(expectedString, actualString);
}

@Test
Expand All @@ -161,7 +159,7 @@ public void rpcByteArrayDataSource_No_Generic_To_List_byte() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
List<byte[]> actualBytes = (List) actualArg.getValue();
String actualString = new String(actualBytes.get(0));
assertEquals(actualString, expectedString);
assertEquals(expectedString, actualString);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import com.microsoft.azure.functions.worker.binding.BindingData;
import com.microsoft.azure.functions.worker.binding.RpcCollectionDoubleDataSource;
import org.apache.commons.lang3.reflect.TypeUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.lang.invoke.WrongMethodTypeException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

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

public class RpcCollectionDoubleDataSourceTest {
@Test
Expand All @@ -34,7 +34,7 @@ public void rpcCollectionDoubleDataSource_To_Double_Object_Array() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
Double[] actualDoublegArray = (Double[]) actualArg.getValue();
Double actualDouble = actualDoublegArray[0];
assertEquals(actualDouble, expectedDouble);
assertEquals(expectedDouble, actualDouble);
}

@Test
Expand All @@ -56,7 +56,7 @@ public void rpcCollectionDoubleDataSource_To_double_Array() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
double[] actualDoubleArray = (double[]) actualArg.getValue();
double actualDouble = actualDoubleArray[0];
assertEquals("" + actualDouble, "" + expectedDouble);
assertEquals(expectedDouble, actualDouble);
}

@Test
Expand All @@ -78,7 +78,7 @@ public void rpcCollectionDoubleDataSource_default_To_List_Double() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
List<Double> actualDoubleList = (List) actualArg.getValue();
Double actualLong = actualDoubleList.get(0);
assertEquals(actualLong, expectedDouble);
assertEquals(expectedDouble, actualLong);
}

@Test
Expand All @@ -100,7 +100,7 @@ public void rpcCollectionDoubleDataSource_To_List_Double() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
List<Double> actualDoubleList = (List) actualArg.getValue();
Double actualLong = actualDoubleList.get(0);
assertEquals(actualLong, expectedDouble);
assertEquals(expectedDouble, actualLong);
}

@Test
Expand All @@ -122,7 +122,7 @@ public void rpcCollectionDoubleDataSource_No_Generic_To_List_Long() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
List<Double> actualDoubleList = (List) actualArg.getValue();
Double actualLong = actualDoubleList.get(0);
assertEquals(actualLong, expectedDouble);
assertEquals(expectedDouble, actualLong);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import com.microsoft.azure.functions.worker.binding.BindingData;
import com.microsoft.azure.functions.worker.binding.RpcCollectionLongDataSource;
import org.apache.commons.lang3.reflect.TypeUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.lang.invoke.WrongMethodTypeException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

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

public class RpcCollectionLongDataSourceTest{
@Test
Expand All @@ -34,7 +34,7 @@ public void rpcCollectionSInt64DataSource_To_Long_Object_Array() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
Long[] actualLongArray = (Long[]) actualArg.getValue();
Long actualLong = actualLongArray[0];
assertEquals(actualLong, expectedLong);
assertEquals(expectedLong, actualLong);
}

@Test
Expand All @@ -56,7 +56,7 @@ public void rpcCollectionDoubleDataSource_To_long_Array() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
long[] actualLongArray = (long[]) actualArg.getValue();
Long actualLong = actualLongArray[0];
assertEquals(actualLong, expectedLong);
assertEquals(expectedLong, actualLong);
}

@Test
Expand All @@ -78,7 +78,7 @@ public void rpcCollectionSInt64DataSource_default_To_List_Long() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
List<Long> actualLongList = (List) actualArg.getValue();
Long actualLong = actualLongList.get(0);
assertEquals(actualLong, expectedLong);
assertEquals(expectedLong, actualLong);
}

@Test
Expand All @@ -101,7 +101,7 @@ public void rpcCollectionSInt64DataSource_To_List_Long() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
List<Long> actualLongList = (List) actualArg.getValue();
Long actualLong = actualLongList.get(0);
assertEquals(actualLong, expectedLong);
assertEquals(expectedLong, actualLong);
}

@Test
Expand All @@ -124,6 +124,6 @@ public void rpcCollectionSInt64DataSource_No_Generic_To_List_Long() {
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
List<Long> actualLongList = (List) actualArg.getValue();
Long actualLong = actualLongList.get(0);
assertEquals(actualLong, expectedLong);
assertEquals(expectedLong, actualLong);
}
}
Loading