I'm using scala_specs2_junit_test test rule and I want to pass the test a system property (what you can usually do with -DmyProp=myValue.
I found this thread which sounds related but it talks about java (native rule which has access to command line arguments) and run (vs test).
Is this possible?
You can use --test_arg, but the test rule itself must interpret such flags.
The scala_specs2_junit_test macro wraps a scala_junit_test rule. As a test rule, the latter must write ctx.outputs.executable (see rule()#test) which is what Bazel executes upon bazel test //my:test and passes the --test_arg flags to.
I didn't find any logic in the Scala rules that would parse --jvm_flags flags, so it seems they need to be updated to handle that.
Demo
<workspace>/my_test.bzl:
def _my_test_impl(ctx):
ctx.file_action(
ctx.outputs.executable,
"\n".join([
"#!/bin/bash",
"echo \"DEBUG: Hello from $(basename $0)\"",
"echo \"DEBUG: Argv=($#)\"",
# Flag parsing (e.g. --jvm_flags) would have to happen here
]),
True)
my_test = rule(
implementation = _my_test_impl,
test = True,
)
<workspace>/BUILD:
load("//:my_test.bzl", "my_test")
my_test(
name = "my_test",
)
Output:
$ bazel test //:my_test --test_output=streamed -t- --test_arg=--foo=bar --test_arg=--jvm_flags=blah
(...)
INFO: (14:45:05.379) Found 1 test target...
DEBUG: Hello from my_test
DEBUG: Argv=(--foo=bar --jvm_flags=blah)
Target //:my_test up-to-date:
bazel-bin/my_test
INFO: (14:45:05.501) Elapsed time: 0.393s, Critical Path: 0.11s
INFO: (14:45:05.501) Build completed successfully, 3 total actions
//:my_test PASSED in 0.1s
EDIT: added comment to my_test.bzl to highlight where the flag parsing would happen
You can always set a system property in Java programatically using System.setProperty(name, value).
The drawback to doing this in a unit test is that the property will stay set after the test. Make sure you set the value to null after the test.
Related
I am using com.cloudera.crunch version: '0.3.0-3-cdh-5.2.1'.
I have a small program that reads some AVROs and filters out invalid data based on some criteria. I am using pipeline.write(PCollection, AvroFileTarget) to write the invalid data output. It works fine in production run.
For unit testing this piece of code, I use MemPipeline instance.
But, it fails while writing the output in that case.
I get error:
java.lang.UnsatisfiedLinkError: org.apache.hadoop.util.NativeCrc32.nativeComputeChunkedSumsByteArray(II[BI[BIILjava/lang/String;JZ)V
at org.apache.hadoop.util.NativeCrc32.nativeComputeChunkedSumsByteArray(Native Method)
at org.apache.hadoop.util.NativeCrc32.calculateChunkedSumsByteArray(NativeCrc32.java:86)
at org.apache.hadoop.util.DataChecksum.calculateChunkedSums(DataChecksum.java:428)
at org.apache.hadoop.fs.FSOutputSummer.writeChecksumChunks(FSOutputSummer.java:197)
at org.apache.hadoop.fs.FSOutputSummer.flushBuffer(FSOutputSummer.java:163)
at org.apache.hadoop.fs.FSOutputSummer.flushBuffer(FSOutputSummer.java:144)
at org.apache.hadoop.fs.FSOutputSummer.write(FSOutputSummer.java:78)
at org.apache.hadoop.fs.FSDataOutputStream$PositionCache.write(FSDataOutputStream.java:50)
at java.io.DataOutputStream.writeBytes(DataOutputStream.java:276)
at com.cloudera.crunch.impl.mem.MemPipeline.write(MemPipeline.java:159)
Any idea what's wrong?
Hadoop environment variable should be configured properly along with hadoop.dll and winutils.exe.
Also pass the JVM argument while executing MR job/application
-Djava.library.path=HADOOP_HOME/lib/native
I have a feature file with 5 scenarios :
#Scenario_1
#labelA
Given....
#Scenario_2
#labelB
Given....
#Scenario_3
#labelA
Given....
#Scenario_4
#labelA
Given...
#Scenario_5
#labelB
Given...
On my system, it executes in the same order in which it is present on the FF - 1,2,3,4,5. However, on a VM, it executes in any random order, like 4,1,5,3,2.
I need 1 to be compulsorily executed before 2, and 2 to be compulsorily executed before 3 and so on. Is there a way to force Cucumber to run the scenarios in the order in which they are present in the feature file ?
to do this one way is : to order the features at the lauching of the cucumber executable :
i.e.
./cucumber.sh myfeatures\second\1.feature features\first\2.feature features
where will be executed in order:
myfeatures\second\1.feature, then
features\first\2.feature, then
features.
With reference to my previous question,
Executing a lisp function from Java
I was able to call lisp code from Java using ABCL.
But the problem is, the already existing lisp code uses CL-PPCRE package.
I can not compile the code as it says 'CL-PPCRE not found'.
I have tried different approaches to add that package,
including
1) how does one compile a clisp program which uses cl-ppcre?
2)https://groups.google.com/forum/#!topic/cl-ppcre/juSfOhEDa1k
Doesnot work!
Other thing is, that executing (compile-file aima.asd) works perfectly fine although it does also require cl-pprce
(defpackage #:aima-asd
(:use :cl :asdf))
(in-package :aima-asd)
(defsystem aima
:name "aima"
:version "0.1"
:components ((:file "defpackage")
(:file "main" :depends-on ("defpackage")))
:depends-on (:cl-ppcre))
The final java code is
interpreter.eval("(load \"aima/asdf.lisp\")");
interpreter.eval("(compile-file \"aima/aima.asd\")");
interpreter.eval("(compile-file \"aima/defpackage.lisp\")");
interpreter.eval("(in-package :aima)");
interpreter.eval("(load \"aima/aima.lisp\")");
interpreter.eval("(aima-load 'all)");
The error message is
Error loading C:/Users/Administrator.NUIG-1Z7HN12/workspace/aima/probability/domains/edit-nets.lisp at line 376 (offset 16389)
#<THREAD "main" {3A188AF2}>: Debugger invoked on condition of type READER-ERROR
The package "CL-PPCRE" can't be found.
[1] AIMA(1):
Can anyone help me?
You need to load cl-ppcre before you can use it. You can do that by using (asdf:load-system :aima), provided that you put both aima and cl-ppcre into locations that your ASDF searches.
I used QuickLisp to add cl-ppcre (because nothing else worked for me).
Here is what I did
(load \"~/QuickLisp.lisp\")")
(quicklisp-quickstart:install)
(load "~/quicklisp/setup.lisp")
(ql:quickload :cl-ppcre)
First 2 lines are only a one time things. Once quickLisp is installed you can start from line 3.
I have a Perl script that uses Inline::Java and just has to fork (it is a server and I want it to handle multiple connections simultaneously).
So I wanted to implement this solution which makes use of a shared JVM with SHARED_JVM => 1. Since the JVM is not shutdown when the script exits, I want to reuse it with START_JVM => 0. But since it might just be the first time I start the server, I would also like to have a BEGIN block make sure a JVM is running before calling use Inline.
My question is very simple, but I couldn't find any answer on the web: How do I simply start a JVM? I've looked at man java and there seems to be just no option that means "start and just listen for connections".
Here is a simplified version of what I'm trying to do in Perl, if this helps:
BEGIN {
&start_jvm unless &jvm_is_running;
}
use Inline (
Java => 'STUDY',
SHARED_JVM => 1,
START_JVM => 0,
STUDY => ['JavaStuff'],
);
if (fork) {
JavaStuff->do_something;
wait;
}
else {
Inline::Java::reconnect_JVM();
JavaStuff->do_something;
}
What I need help with is writing the start_jvm subroutine.
If you've got a working jvm_is_running function, just use it to determine whether Inline::Java should start the JVM.
use Inline (
Java => 'STUDY',
SHARED_JVM => 1,
START_JVM => jvm_is_running() ? 0 : 1,
STUDY => ['JavaStuff'],
);
Thanks to details provided by tobyink, I am able to answer my own question, which was based on a the erroneous assumption that the JVM itself provides a server and a protocole.
As a matter of fact, one major component of Inline::Java is a server, written in Java, which handles request by the Inline::Java::JVM client, written in Perl.
Therefore, the command-line to launch the server is:
$ java org.perl.inline.java.InlineJavaServer <DEBUG> <HOST> <PORT> <SHARED_JVM> <PRIVATE> <NATIVE_DOUBLES>
where all parameters correspond to configuration options described in the Inline::Java documentation.
Therefore, in my case, the start_jvm subroutine would be:
sub start_jvm {
system
'java org.perl.inline.java.InlineJavaServer 0 localhost 7891 true false false';
}
(Not that it should be defined: tobyink's solution, while it did not directly address the question I asked, is much better.)
As for the jvm_is_running subroutine, this is how I defined it:
use Proc::ProcessTable;
use constant {
JAVA => 'java',
INLINE_SERVER => 'org.perl.inline.java.InlineJavaServer',
};
sub jvm_is_running {
my $pt = new Proc::ProcessTable;
return grep {
$_->fname eq JAVA && ( split /\s/, $_->cmndline )[1] eq INLINE_SERVER
} #{ $pt->table };
}
I have some classes that implement interfaces, some of which have methods whose parameters are by definition unused in the particular class implementation. e.g. A "Shape" interface may define a "contains(point)" method, but my particular class defines a line, which cannot contain anything since it's 1-dimensional, so it always returns false and never uses point.
However, when I compile with GCJ, I'm assaulted with hundreds of "warning: parameter x is unused" messages.
I tried using the -Wno-all flag to disable warnings, as well as the others documented in gcj's manpage, but these have no effect. How do I instruct GCJ to not bother me with these trivial warnings?
I've managed to disable all warnings affecting my source code using:
gcj -Wno-all -Wno-unchecked -Wno-raw *.java
You may want to add more -Wno-... flags to disable more warnings. To figure out the possible flags, I examined the body of the methods org.eclipse.jdt.internal.compiler.batch.Main.handleWarningToken and org.eclipse.jdt.internal.compiler.batch.Main.handleErrorOrWarningToken in the Eclipse Batch Compiler ecjsrc-3.5.2.zip and ecjsrc-3.8.zip.
Specify all these flags to get all warnings disabled:
-Wno-all
-Wno-allDeadCode
-Wno-allDeprecation
-Wno-allJavadoc
-Wno-allOver-ann
-Wno-all-static-method
-Wno-assertIdentifier
-Wno-boxing
-Wno-charConcat
-Wno-compareIdentical
-Wno-conditionAssign
-Wno-constructorName
-Wno-deadCode
-Wno-dep-ann
-Wno-deprecation
-Wno-discouraged
-Wno-emptyBlock
-Wno-enumIdentifier
-Wno-enumSwitch
-Wno-enumSwitchPedantic
-Wno-fallthrough
-Wno-fieldHiding
-Wno-finalBound
-Wno-finally
-Wno-forbidden
-Wno-hashCode
-Wno-hiding
-Wno-includeAssertNull
-Wno-incomplete-switch
-Wno-indirectStatic
-Wno-interfaceNonInherited
-Wno-intfAnnotation
-Wno-intfNonInherited
-Wno-intfRedundant
-Wno-javadoc
-Wno-localHiding
-Wno-maskedCatchBlock
-Wno-maskedCatchBlocks
-Wno-nls
-Wno-noEffectAssign
-Wno-noImplicitStringConversion
-Wno-null
-Wno-nullDereference
-Wno-over-ann
-Wno-over-sync
-Wno-packageDefaultMethod
-Wno-paramAssign
-Wno-pkgDefaultMethod
-Wno-raw
-Wno-redundantSuperinterface
-Wno-resource
-Wno-semicolon
-Wno-serial
-Wno-specialParamHiding
-Wno-static-access
-Wno-static-method
-Wno-staticReceiver
-Wno-super
-Wno-suppress
-Wno-switchDefault
-Wno-syncOverride
-Wno-synthetic-access
-Wno-syntheticAccess
-Wno-typeHiding
-Wno-unavoidableGenericProblems
-Wno-unchecked
-Wno-unnecessaryElse
-Wno-unqualifiedField
-Wno-unqualified-field-access
-Wno-unsafe
-Wno-unused
-Wno-unusedAllocation
-Wno-unusedArgument
-Wno-unusedArguments
-Wno-unusedImport
-Wno-unusedImports
-Wno-unusedLabel
-Wno-unusedLocal
-Wno-unusedLocals
-Wno-unusedPrivate
-Wno-unusedThrown
-Wno-unusedTypeArgs
-Wno-uselessTypeCheck
-Wno-varargsCast
-Wno-warningToken
Although I haven't found an option to do this directly with gcj, one workaround is to pipe the output into grep and look for the pattern "error:", and then only show that line and a few surrounding lines.
e.g.
javac *.java 2>&1 | grep -B 3 -A 2 "error:"