use of org.ballerinalang.launcher.util.CompileResult in project ballerina by ballerina-lang.
the class SQLTest method testSelectWithUntaintedQueryProducingTaintedReturnNegative.
@Test
public void testSelectWithUntaintedQueryProducingTaintedReturnNegative() {
CompileResult result = BCompileUtil.compile("test-src/taintchecking/connectors/sql-select-untainted-query-tainted-return-negative.bal");
Assert.assertTrue(result.getDiagnostics().length == 1);
BAssertUtil.validateError(result, 0, "tainted value passed to sensitive parameter 'anyValue'", 29, 50);
}
use of org.ballerinalang.launcher.util.CompileResult in project ballerina by ballerina-lang.
the class TimerTest method testExecutionWithWorkersAndErrorFn.
@Test(description = "Tests running a timer started within workers where the onTrigger function generates an error")
public void testExecutionWithWorkersAndErrorFn() {
CompileResult timerCompileResult = BCompileUtil.compileAndSetup("test-src/task/timer-workers.bal");
printDiagnostics(timerCompileResult);
int w1InitialDelay = 500;
int w1Interval = 1000;
int w2InitialDelay = 800;
int w2Interval = 1000;
String w1ErrMsg = "w1: Timer error";
String w2ErrMsg = "w2: Timer error";
BValue[] returns = BRunUtil.invokeStateful(timerCompileResult, "scheduleTimer", new BValue[] { new BInteger(w1InitialDelay), new BInteger(w1Interval), new BInteger(w2InitialDelay), new BInteger(w2Interval), new BString(w1ErrMsg), new BString(w2ErrMsg) });
String w1TaskId = returns[0].stringValue();
String w2TaskId = returns[1].stringValue();
// A non-null task ID should be returned
assertNotEquals(w1TaskId, "", "Invalid task ID from worker w1");
// A non-null task ID should be returned
assertNotEquals(w2TaskId, "", "Invalid task ID from worker w2");
await().atMost(10, SECONDS).until(() -> {
BValue[] errors = BRunUtil.invokeStateful(timerCompileResult, "getErrors");
return errors != null && errors[0] != null && !errors[0].stringValue().isEmpty() && errors[1] != null && !errors[1].stringValue().isEmpty();
});
// Now test whether the onError Ballerina function got called
BValue[] error = BRunUtil.invokeStateful(timerCompileResult, "getErrors");
assertNotNull(error[0], "Expected error not returned.");
assertEquals(error[0].stringValue(), w1ErrMsg, "Expected error message not returned.");
assertEquals(error[1].stringValue(), w2ErrMsg, "Expected error message not returned.");
// Now let's try stopping the tasks
BValue[] stopResult = BRunUtil.invokeStateful(timerCompileResult, "stopTasks", new BValue[] { new BString(w1TaskId), new BString(w2TaskId) });
assertNull(stopResult[0], "Task stopping on worker w1 resulted in an error");
assertNull(stopResult[1], "Task stopping on worker w2 resulted in an error");
// One more check to see whether the task really stopped
BValue[] counts = BRunUtil.invokeStateful(timerCompileResult, "getCounts");
assertEquals(((BInteger) counts[0]).intValue(), -1, "Count hasn't been reset");
assertEquals(((BInteger) counts[1]).intValue(), -1, "Count hasn't been reset");
}
use of org.ballerinalang.launcher.util.CompileResult in project ballerina by ballerina-lang.
the class TimerTest method testSimpleExecutionWithWorkers.
@Test(description = "Tests running a timer started within workers")
public void testSimpleExecutionWithWorkers() {
CompileResult timerCompileResult = BCompileUtil.compileAndSetup("test-src/task/timer-workers.bal");
printDiagnostics(timerCompileResult);
int w1InitialDelay = 500;
int w1Interval = 1000;
int w2InitialDelay = 800;
int w2Interval = 2000;
BValue[] returns = BRunUtil.invokeStateful(timerCompileResult, "scheduleTimer", new BValue[] { new BInteger(w1InitialDelay), new BInteger(w1Interval), new BInteger(w2InitialDelay), new BInteger(w2Interval), new BString(""), new BString("") });
String w1TaskId = returns[0].stringValue();
String w2TaskId = returns[1].stringValue();
// A non-null task ID should be returned
assertNotEquals(w1TaskId, "", "Invalid task ID from worker w1");
// A non-null task ID should be returned
assertNotEquals(w2TaskId, "", "Invalid task ID from worker w2");
await().atMost(30, SECONDS).until(() -> {
BValue[] counts = BRunUtil.invokeStateful(timerCompileResult, "getCounts");
return counts != null && counts[0] != null && counts[1] != null && ((BInteger) counts[0]).intValue() >= 5 && ((BInteger) counts[1]).intValue() >= 5;
});
// Now let's try stopping the tasks
BValue[] stopResult = BRunUtil.invokeStateful(timerCompileResult, "stopTasks", new BValue[] { new BString(w1TaskId), new BString(w2TaskId) });
assertNull(stopResult[0], "Task stopping on worker w1 resulted in an error");
assertNull(stopResult[1], "Task stopping on worker w2 resulted in an error");
// One more check to see whether the task really stopped
BValue[] counts = BRunUtil.invokeStateful(timerCompileResult, "getCounts");
assertEquals(((BInteger) counts[0]).intValue(), -1, "Count hasn't been reset");
assertEquals(((BInteger) counts[1]).intValue(), -1, "Count hasn't been reset");
}
use of org.ballerinalang.launcher.util.CompileResult in project ballerina by ballerina-lang.
the class BAnyTypeInvalidCastError method testInvalidAnyCasting.
@Test
public void testInvalidAnyCasting() {
CompileResult resultNegative = BCompileUtil.compile("test-src/types/any/any-type-cast-negative.bal");
Assert.assertEquals(resultNegative.getErrorCount(), 2);
BAssertUtil.validateError(resultNegative, 0, 3, 15);
BAssertUtil.validateErrorMessageOnly(resultNegative, 0, "incompatible types: expected 'float', found ");
BAssertUtil.validateErrorMessageOnly(resultNegative, 0, new String[] { "float|error", "error|float" });
BAssertUtil.validateError(resultNegative, 1, 14, 11);
BAssertUtil.validateErrorMessageOnly(resultNegative, 1, "incompatible types: expected 'int', found ");
BAssertUtil.validateErrorMessageOnly(resultNegative, 1, new String[] { "int|error", "error|int" });
// TODO: This needs to have another error, for casting a null value. Add that check when it's fixed.
}
use of org.ballerinalang.launcher.util.CompileResult in project ballerina by ballerina-lang.
the class StructTest method testStructLiteralInitFunc.
@Test
public void testStructLiteralInitFunc() {
CompileResult result = BCompileUtil.compile("test-src/structs/nested-struct-inline-init.bal");
BValue[] returns = BRunUtil.invoke(result, "testCreateStruct");
Assert.assertEquals(returns[0].stringValue(), "{name:\"default first name\", fname:\"\", lname:\"Doe\", adrs:{}, age:999, " + "family:{spouse:\"Jane\", noOfChildren:0, children:[\"Alex\", \"Bob\"]}}");
}
Aggregations