我想关闭1个单元测试的日志记录(这不会失败),因此stacktrace不会显示在日志中。该堆栈跟踪应该在生产运行中存在,因为它是一个故障测试测试。
生产代码如下所示:
boolean failed = false;
for (int i = 0; i < 10; i++) {
try {
// Possible submits on Executor to run on other thread (not that it matters)
runTask(i);
} catch (RuntimeException e) {
// In the unit test, this pollutes the test log // BAD, MY PROBLEM
// In production, it shows up in the log immediately, before other tasks run // GOOD
logger.warn("Task failed. Stacktrace:", e);
failed = true;
}
}
if (failed) { …Run Code Online (Sandbox Code Playgroud) 我的 web 应用程序beans.xml在src/main/resources/META-INF. 现在,对于我的测试,我需要用替代品替换 1 个 bean。
beans.xml我应该把这个只包含这个而没有更多内容的测试放在哪里?
<?xml version="1.0" encoding="UTF-8"?>
<beans ...>
<alternatives>
<class>...MyTestReplacement</class>
</alternatives>
</beans>
Run Code Online (Sandbox Code Playgroud)
我试过了,src/test/resources/META-INF但被忽略了。我正在使用 arquillian,并且我的测试类路径已添加到 ShrinkWrap 中。
我想在服务器计算机的后台运行一个shell脚本,并从ssh连接启动该shell脚本.即使我运行后台进程脚本nohup,后台脚本在我关闭ssh连接时(并且不久)就会因目录无法访问错误而失败.
runInBackground.sh:
#!/bin/bash
...
nohup ./run.sh > /dev/null 2> local/errorLog.txt < /dev/null &
Run Code Online (Sandbox Code Playgroud)
run.sh:
#!/bin/bash
...
while [ true ] ; do
...
cd optaplanner-examples
mvn exec:exec // calls java process
cd ..
done
Run Code Online (Sandbox Code Playgroud)
因此,当我运行时runInBackground.sh,一切都运行好几个小时,直到我断开我的ssh连接.一旦我退出,errorlog.txt填满:
java.io.FileNotFoundException: /home/myUser/server/optaplanner-simple-benchmark-daemon/local/output/
./run.sh: line 64: /home/myUser/server/optaplanner-simple-benchmark-daemon/local/processed/failed_machineReassignmentBenchmarkConfig.xml: No such file or directory
fatal: Could not change back to '(unreachable)/server/optaplanner-simple-benchmark-daemon/local/optaplannerGitClone/optaplanner': No such file or directory
ls: cannot access /home/myUser/server/optaplanner-simple-benchmark-daemon/local/input: No such file …Run Code Online (Sandbox Code Playgroud) 在运行时,在我的Java程序中,给定一个String,我想知道返回类型.例如:
1 + 1 回报 int1L + 1L 回报 long1L + 1 回报 long1 + 1.5 回报 double1 + 2 - 3 * 4 / 5 回报 int1 / 0 回报 int1 + Math.nextInt() 回报 int1.5 + Math.nextInt() 回报 doubleColor.RED 回报 java.awt.Colora是一个int:a + 1returninta是一个int:a + 1.5returndouble没有必要实际评估代码:我只需要返回类型.如何使用JDK运行时编译器,ECJ JDT或任何其他纯Java依赖项执行此操作?
详细代码:以下是此代码的简化伪代码单元测试:
public static void ExpressionTyper {
public String determineType(String expression, Map<String, …Run Code Online (Sandbox Code Playgroud) 我正在开发一个Web应用程序并将其(使用IntelliJ)部署到WildFly 10.1。我最近将我的webapp模块重命名,这将我的war文件从重命名foo.war为bar.war。每次启动时,都会出现以下错误:
12:24:15,899 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC000001: Failed to start service jboss.deployment.unit."foo_war_exploded.war".STRUCTURE: org.jboss.msc.service.StartException in service jboss.deployment.unit."foo_war_exploded.war".STRUCTURE: WFLYSRV0153: Failed to process phase STRUCTURE of deployment "foo_war_exploded.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:154)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYSRV0160: Failed to mount deployment content
at org.jboss.as.server.deployment.module.DeploymentRootMountProcessor.deploy(DeploymentRootMountProcessor.java:95)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:147)
... 5 more
Caused by: java.io.FileNotFoundException: /.../foo_war_exploded (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at org.jboss.vfs.spi.RootFileSystem.openInputStream(RootFileSystem.java:51) …Run Code Online (Sandbox Code Playgroud) 假设我有一个列表列表,如下所示:
因此外部列表的大小为3,内部列表的大小为5,3和4.
我需要获得任何这些内部列表的随机元素,给出每个元素同样随机的机会.所以我可以编写一个算法:
0和之间生成随机数totalListsSize (5 + 3 + 4) = 12randomIndex 7randomIndex 7 - firstListSize 5 = newRandomIndex 2randomIndex 2 in secondList = element g.问题是顺序选择必须完整且可耗尽:在上面的例子中经过12次连续选择后,我必须选择每个元素一次.
有没有办法做到可扩展?
randomIndex.在Freemarker FTL文件中,我要调用StringUtils.capatilize(myString)。例如:
<p>You selected ${selectionString}.</p>
<p>${StringUtils.capatilize(selectionString)} is great.</p>
Run Code Online (Sandbox Code Playgroud)
我能以某种方式进口 org.apache.commons.lang3.StringUtils吗?
从JUnit 3到JUnit 4这个问题的精神,是否有任何正则表达式列表可以有效地从junit 4 API迁移到junit 5 API,无论代码大小如何?
我们有一个项目要求通过Web应用程序访问guvnor.任何人都可以让我知道如何通过Java代码访问guvnor?
计算机具有RAM内存,但它也具有小巧,快速的CPU内存缓存.Java内存模型保证在访问变量时刷新CPU内存缓存volatile,但由于我们只在单个线程中的单个类中使用该volatile变量,因此不确定JIT是否只是优化它.
为了诊断一个bug(当我们在某个时刻调用Thread.sleep()足够长时才会出现这个bug),我们需要能够做这样的事情(而不是sleep()):
System.clearCpuCache();
Run Code Online (Sandbox Code Playgroud)
实现这种方法的最简单,最可靠的方法是什么?它应该保证它不会JIT优化缓存刷新.我们只能在启用JIT的情况下重现我们的错误,因此禁用JIT不是一种选择.
我有一个学校项目,为2D赛车游戏建立一个AI,它将与其他几个AI竞争.
我们获得了赛道的黑白位图图像,我们可以在收到地图后选择我们的汽车的基本属性(操控,加速,最大速度和制动).AI连接到游戏的服务器,并为当前加速和转向提供几次秒数.顺便说一句,我选择的语言是C++.问题是
java ×6
algorithm ×1
bash ×1
c++ ×1
collections ×1
concurrency ×1
drools ×1
ecj ×1
freemarker ×1
jboss ×1
jboss-weld ×1
junit ×1
junit4 ×1
junit5 ×1
linux ×1
logback ×1
logging ×1
random ×1
reflection ×1
shell ×1
slf4j ×1
synchronized ×1
volatile ×1
wildfly ×1
wildfly-10 ×1