Skip to content

Commit

Permalink
Merge with origin branch
Browse files Browse the repository at this point in the history
  • Loading branch information
warunalakshitha committed Nov 6, 2023
2 parents 8eb4ce8 + d73e7e6 commit 5e36cc5
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -51,13 +53,29 @@ public void setup() throws BallerinaTestException {

@Test
public void testProfilerExecutionWithBalPackage() throws BallerinaTestException {
String sourceRoot = testFileLocation + "/";
String packageName = "projectForProfile/package_a";
String sourceRoot = testFileLocation + "/";
Map<String, String> envProperties = new HashMap<>();
bMainInstance.addJavaAgents(envProperties);
LogLeecher[] leechers = getProfilerLogLeechers(packageName + "/target/bin/" + outputFile);
bMainInstance.runMain("profile", new String[]{packageName}, envProperties,
null, leechers, sourceRoot);
bMainInstance.runMain("profile", new String[]{packageName}, envProperties, null,
leechers, sourceRoot);
for (LogLeecher leecher : leechers) {
leecher.waitForText(5000);
}
}

@Test
public void testProfilerExecutionWithConfigurableVars() throws BallerinaTestException {
String packageName = "projectForProfile/package_b";
String sourceRoot = testFileLocation + "/" + packageName;
Map<String, String> envProperties = new HashMap<>();
bMainInstance.addJavaAgents(envProperties);
List<LogLeecher> leechers = new ArrayList<>(Arrays.asList(
getProfilerLogLeechers(packageName + "/target/bin/" + outputFile)));
leechers.add(new LogLeecher("Tests passed"));
bMainInstance.runMain("profile", new String[]{}, envProperties, null,
leechers.toArray(new LogLeecher[0]), sourceRoot);
for (LogLeecher leecher : leechers) {
leecher.waitForText(5000);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
org = "foo"
name = "package_b"
version = "0.1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
intValue = 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import foo/package_b.mod_a1;
import ballerina/test;
import ballerina/jballerina.java;

configurable int intValue = ?;

public function main() {
int a = mod_a1:func1() + intValue;
test:assertEquals(a, 30);
print("Tests passed");
}

function print(string value) {
handle strValue = java:fromString(value);
handle stdout1 = stdout();
printInternal(stdout1, strValue);
}

public function stdout() returns handle = @java:FieldGet {
name: "out",
'class: "java/lang/System"
} external;

public function printInternal(handle receiver, handle strValue) = @java:Method {
name: "println",
'class: "java/io/PrintStream",
paramTypes: ["java.lang.String"]
} external;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

boolean num = float:isFinite(1.0);
int a = 10;

public function func1() returns int {
if (num) {
a = 20;
} else {
a = 30;
}
return a;
}

0 comments on commit 5e36cc5

Please sign in to comment.