小编sig*_*ned的帖子

尽管快速执行,JUnit测试"超时"?

我有几个测试用例,当整个测试运行只持续几秒钟时,JUnit会告诉我10000毫秒的时间.这是输出:

Tests run: 3, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 2.528 sec <<< FAILURE!
closeTest1(com.w2ogroup.analytics.sibyl.transport.impl.http.server.HttpServerTransportTests)  Time elapsed: 1.654 sec  <<< ERROR!
java.lang.Exception: test timed out after 10000 milliseconds

closeTest2(com.w2ogroup.analytics.sibyl.transport.impl.http.server.HttpServerTransportTests)  Time elapsed: 0.672 sec  <<< ERROR!
java.lang.Exception: test timed out after 50000 milliseconds


Results :

Tests in error:
  HttpServerTransportTests »  test timed out after 10000 milliseconds
  HttpServerTransportTests »  test timed out after 50000 milliseconds

Tests run: 3, Failures: 0, Errors: 2, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] …
Run Code Online (Sandbox Code Playgroud)

java junit junit4 maven-surefire-plugin

10
推荐指数
1
解决办法
6803
查看次数

为什么这种方法成为热点?

我正在写一个(简单!)线性代数库.在执行矩阵乘法,一个VisualVM的性能样品是告诉我,该算法在下面的方法乘以大矩阵(5K X 120K)时花费的它的时间为85%("自我时间",具体地):

public double next() {
    double result;

    if(hasNext())
        result = vis[i++].next();
    else
        throw new IllegalStateException("No next value");

    return result;
}
Run Code Online (Sandbox Code Playgroud)

没有太多细节(抱歉,我不能共享更多代码),这个方法是next()矩阵的"迭代器" 的方法.(你可以把这个方法住在如由单独的列迭代器,这都存放在一排迭代器之类的vis).我并不感到惊讶,这种方法被调用了很多,因为它是一个迭代器,但我感到惊讶的是,该程序花了很多时间这个方法上.这种方法做得不多,为什么要花时间在这里呢?

以下是我要问的具体问题:

  1. 我正在打击VisualVM的某些"陷阱"吗?例如,JIT是否会以某种方式混淆VisualVM,导致VisualVM将时间归因于错误的方法?
  2. 为什么该计划会花时间在这里?该方法并没有做太多.具体而言,我不认为因为缓存的效果解释这个问题vis阵列要小于乘以矩阵的数据.

如果它有用,这里是我上面粘贴的方法的jad反汇编:

public double next()
{
    double result;
    if(hasNext())
//*   0    0:aload_0         
//*   1    1:invokevirtual   #88  <Method boolean hasNext()>
//*   2    4:ifeq            32
        result = vis[i++].next();
//    3    7:aload_0         
//    4    8:getfield        #42  <Field VectorIterator[] vis>
//    5 …
Run Code Online (Sandbox Code Playgroud)

java optimization performance visualvm

8
推荐指数
1
解决办法
1909
查看次数

在"测试"执行阶段排除"提供的"范围依赖关系?

provided在测试执行期间,我在类路径中看到一个带有范围的jar .鉴于provided范围的定义,我不希望jar在任何执行阶段出现在类路径上.

我已使用M2E"Dependency Hierarchy"视图确认范围是正确的.我已经尝试使用该classpathDependencyScopeExclude选项maven-surefire-plugin来保持依赖关系不显示,并且它没有工作:

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.14.1</version>
        <configuration>
          <!--
            We always want to exclude provided deps. I'm not sure why this
            isn't the default.
          -->
          <classpathDependencyScopeExclude>provided</classpathDependencyScopeExclude>
        </configuration>
      </plugin>
    </plugins>
  </pluginManagement>
</build>
Run Code Online (Sandbox Code Playgroud)

这是有问题的依赖关系定义:

父POM:

<dependency>
  <groupId>javax.ws.rs</groupId>
  <artifactId>jsr311-api</artifactId>
  <version>1.1.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

模块POM:

<dependency>
  <groupId>javax.ws.rs</groupId>
  <artifactId>jsr311-api</artifactId>
  <scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

罐子在那里是正常的吗?我该怎么做以防止它出现?

编辑:我mvn dependency:tree在父POM上运行.这是有问题的项目的输出:

[INFO] ------------------------------------------------------------------------
[INFO] Building sibyl.transport.impl.http.server 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ sibyl.transport.impl.http.server ---
[INFO] …
Run Code Online (Sandbox Code Playgroud)

maven-3 maven

8
推荐指数
1
解决办法
9189
查看次数

sun.reflect中的可能错误.抽象枚举的处理?

我已经确定了什么是至少不良行为,最多是Sun JDK enum使用抽象方法处理Java s 反射的错误.我已经搜索了一个错误报告和StackOverflow对这个特殊行为的回答并且干了.当你认为在如此经常使用且经过仔细测试的代码中发现了这样的问题时,你或多或少总是错的,所以请理智地检查我并告诉我在哪里弄错了.

代码

请考虑以下代码:

A/Greeting.java

package a;

public enum Greeting {
    HELLO {
        @Override
        public void greet() {
            System.out.println("Hello!");
       }
    };
    public abstract void greet();
}
Run Code Online (Sandbox Code Playgroud)

B/EnumTest.java

package b;

import java.lang.reflect.Method;

import a.Greeting;

public class EnumTest {
    public static void main(String[] args) throws Exception {
        Greeting g=Greeting.HELLO;
        Method greet=g.getClass().getMethod("greet");

        System.out.println("Greeting "+g.getClass()+" ...");
        greet.invoke(g);
        System.out.println("Greeted!");
    }
}
Run Code Online (Sandbox Code Playgroud)

此外,请注意,GreetingEnumTest在不同的包装.(这最终很重要.)

错误

运行此代码时,您希望获得以下输出:

Greeting class a.Greeting ...
Hello!
Greeted!
Run Code Online (Sandbox Code Playgroud)

相反,您将获得以下输出:

Greeting class a.Greeting$1 ...
Exception in …
Run Code Online (Sandbox Code Playgroud)

java

7
推荐指数
1
解决办法
875
查看次数

Apache HTTPClient流式HTTP POST请求?

我正在尝试使用Apache HTTPClient构建"全双工"HTTP流式传输请求.

在我的第一次尝试中,我尝试使用以下请求代码:

URL url=new URL(/* code goes here */);

HttpPost request=new HttpPost(url.toString());

request.addHeader("Connection", "close");

PipedOutputStream requestOutput=new PipedOutputStream();
PipedInputStream requestInput=new PipedInputStream(requestOutput, DEFAULT_PIPE_SIZE);
ContentType requestContentType=getContentType();
InputStreamEntity requestEntity=new InputStreamEntity(requestInput, -1, requestContentType);
request.setEntity(requestEntity);

HttpEntity responseEntity=null;
HttpResponse response=getHttpClient().execute(request); // <-- Hanging here
try {
    if(response.getStatusLine().getStatusCode() != 200)
        throw new IOException("Unexpected status code: "+response.getStatusLine().getStatusCode());

    responseEntity = response.getEntity();
}
finally {
    if(responseEntity == null)
        request.abort();
}

InputStream responseInput=responseEntity.getContent();
ContentType responseContentType;
if(responseEntity.getContentType() != null)
    responseContentType = ContentType.parse(responseEntity.getContentType().getValue());
else
    responseContentType = DEFAULT_CONTENT_TYPE;

Reader responseStream=decode(responseInput, responseContentType);
Writer …
Run Code Online (Sandbox Code Playgroud)

java http apache-httpclient-4.x

6
推荐指数
1
解决办法
1万
查看次数

检测异步 JMS MessageConsumer 何时出现异常?

我正在使用MessageConsumer带有MessageListener. 如果发生某些事情导致MessageConsumer停止接收和处理消息——例如,如果底层连接关闭——我如何检测它?我在规范中似乎找不到任何通知机制。

我认为这个问题很清楚,但如果你想让我发布代码来澄清这个问题,那就问吧!

如果它很重要,我使用的是 ActiveMQ 5.8,尽管显然我想要一个不是特定于实现的方案。

java activemq-classic jms mom

5
推荐指数
1
解决办法
970
查看次数

猪相当于SQL GREATEST/LEAST?

我试图找到猪等同的SQL函数GREATESTLEAST.这些功能的聚集SQL函数标量相当于MAXMIN分别.

从本质上讲,我希望能够说出这样的话:

x = LOAD 'file:///a/b/c.csv' USING PigStorage() AS (a: int, b: int, c: int);
y = FOREACH x GENERATE a AS a: int, b AS b: int, c AS c: int, GREATEST(a, b, c) AS g: int;
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用行李并MAX完成这项工作,但我正在将另一种语言翻译成Pig,并且实施起来很难整合.

我可以在这里使用"内联"方法吗?我忽略了一些内置函数,或者可能是Piggybank或DataFu中的UDF,这将是理想的!如果有一个完全"内联"版本使用袋子而我只是没想到它,那也没关系!

谢谢!

apache-pig

3
推荐指数
1
解决办法
341
查看次数