我正在尝试用@InjectMocks和进行单元测试@Mock.
@RunWith(MockitoJUnitRunner.class)
public class ProblemDefinitionTest {
@InjectMocks
ProblemDefinition problemDefinition;
@Mock
Matrix matrixMock;
@Test
public void sanityCheck() {
Assert.assertNotNull(problemDefinition);
Assert.assertNotNull(matrixMock);
}
}
Run Code Online (Sandbox Code Playgroud)
如果我不包含@RunWith注释,则测试失败.但
不推荐使用MockitoJUnitRunner类型
我正在使用Mockito 2.6.9.我该怎么办呢?
我的计算机上有一个旧版本的mingw,它将程序编译为32位.现在我想编译到64位,所以我下载了新的mingw安装程序.它尝试使用不同版本(每次x86_64选项)多次卸载和安装,但每次都会丢失一些文件,至少是make.exe.任何mingw子文件夹中都没有make.exe,只有mingw32-make.exe
C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin
Run Code Online (Sandbox Code Playgroud)
我对c ++比较陌生,所以也许我忽略了什么?https://sourceforge.net/p/mingw-w64/wiki2/Make/提到你可以将make复制到bin文件夹,但是我从哪里复制它?
在尝试设计算法时,我偶然发现了这个问题.这不是功课.
设P_i =第一个i素数的数组.现在我需要最小的i那样
Sum<n=0..i> 1 / (P_i[n]*P_i[n]) >= 1.
Run Code Online (Sandbox Code Playgroud)
(如果i存在的话).
i'th prime 的近似值是i*log(i).所以我在Java中尝试过这个:
public static viod main(String args[]) {
double sum = 0.0;
long i = 2;
while(sum<1.0) {
sum += 1.0 / (i*Math.log(i)*i*Math.log(i));
i++;
}
System.out.println(i+": "+sum);
}
Run Code Online (Sandbox Code Playgroud)
然而,上述情况并未完成,因为它收敛到0.7.然而1/100000000^2,0.0在Java中的轮次,所以这就是为什么它不起作用.出于同样的原因,如果用第6行替换它,它甚至都不起作用
sum += 1.0 / (i*i)
Run Code Online (Sandbox Code Playgroud)
1如果我没有弄错的话应该达到这一点,因为总和应该加快1/2^i,后者收敛1.换句话说,这表明Java舍入导致总和不能达到1.我认为i我的问题至少应该存在.
如何使用Java的Intel i7 Vector处理器(AVX)?这是一个简单的问题,但答案似乎很难找到.
我从另一个不使用 Java 的部门获得了一些 .xsd 文件。我需要编写对应于指定格式的xml。所以我 jaxb 将它们转换为 Java 类,并且我能够编写一些 xml。到现在为止还挺好。但是现在元素/类之一包含一个属性,您可以(/您应该能够)在其中插入任何 xml。我需要在那里插入其他 jaxb 元素之一。
在java中,我们有:
import org.w3c.dom.Element;
...
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"any"
})
public static class XMLDocument {
@XmlAnyElement
protected Element any;
/**
* Gets the value of the any property.
*
* @return
* possible object is
* {@link Element }
*
*/
public Element getAny() {
return any;
}
/**
* Sets the value of the any property.
*
* @param value
* allowed object …Run Code Online (Sandbox Code Playgroud) 很多时候,我在互联网上找到了有用的代码示例.大约一半的时间他们没有指定要包含的文件,甚至没有指定要在命令行中包含-l的库.你通常如何找到它?
编辑说明:以下问题已解决.可以跳过这篇文章的其余部分.
现在,我在尝试编译时遇到了大量错误:
53: string Gunzip::gunzip(string& compressed)
54: {
55: namespace io = boost::iostreams;
56:
57: io::filtering_istream gunzip;
58: gunzip.push(io::gzip_decompressor());
59: std::istringstream in_stream = std::istringstream(compressed);
60: gunzip.push(in_stream);
61:
62: stringstream strstream;
63: io::copy(gunzip, strstream);
64: return strstream.str();
65: }
Run Code Online (Sandbox Code Playgroud)
在互联网上度过一天后,我正在尝试:
option: 3 -L/usr/include/boost
and:
8: #include <string>
9: #include <iostream>
10: #include <sstream>
15: #include <boost/iostreams/copy.hpp>
16: #include <boost/iostreams/device/array.hpp>
17: #include <boost/iostreams/device/back_inserter.hpp>
18: #include <boost/iostreams/filter/gzip.hpp>
19: #include <boost/iostreams/filter/test.hpp>
20: #include <boost/iostreams/filtering_stream.hpp>
Run Code Online (Sandbox Code Playgroud)
我遇到的错误是:
from /usr/include/c++/4.5/string:45,
from Gunzip.cpp:8:
/usr/include/c++/4.5/bits/ios_base.h: In copy constructor …Run Code Online (Sandbox Code Playgroud) 我是一名 Java Spring boot 开发人员,我开发 3 层 CRUD 应用程序。我和一个似乎对这个主题很了解的人交谈过,但我没有得到他的联系方式。他提倡使用 Python 的 FastApi,因为它的水平扩展性比 Spring boot 更好。他提到的原因之一是FastApi是单线程的。当线程遇到数据库查找(或其他可以异步完成的工作)时,它会选择其他工作,以便稍后在数据库结果传入时返回到当前工作。在 Java 中,当有许多请求待处理时,线程池可能会耗尽。
我不能百分百理解这个推理。让我扮演魔鬼代言人。当Python程序遇到异步调用时,它必须以某种方式将程序指针存储在某个地方,以记住稍后需要在哪里继续。我知道存储程序指针的地方根本不是线程,但我必须给它起个名字,所以我们称它为“逻辑线程”。在 Python 中,您可以有许多正在等待的逻辑线程。在 Java 中,您可以拥有一个线程池,其中有许多正在等待的实际线程。对我来说,唯一的区别似乎是 Java 的线程是在操作系统级别管理的,而 Python 的“逻辑线程”是由 Python 或 FastApi 管理的。为什么在线程池中等待的实际线程比等待的逻辑线程要昂贵得多?如果我的大多数线程都在等待,为什么我不能增加线程池大小以避免耗尽?
当尝试在命令行中使用karaf中的install命令将我的应用程序安装为osgi包时,一切似乎都很好.当我输入start(id)时,一切似乎都很好,但我的应用程序似乎不接受请求.当我输入log:display时,我得到了这个:
2016-04-20 13:49:38,251 | INFO | Thread-19 | bundle | 37 - org.apache.aries.spifly.dynamic.bundle - 1.0.1 | Bundle Considered for SPI providers: oms-integrations
2016-04-20 13:49:38,251 | INFO | Thread-19 | bundle | 37 - org.apache.aries.spifly.dynamic.bundle - 1.0.1 | No 'SPI-Provider' Manifest header. Skipping bundle: oms-integrations
Run Code Online (Sandbox Code Playgroud)
我是新手,我不知道这意味着什么("没有'SPI-Provider'Manifest标题.")或者如何解决它?
我在 Java 11(在 Intellij 和 Jenkins 中)中遇到了一个问题,并进行了最小的复制。一位同事认为这是 Java 中的一个错误。
当然,以下编译:
public class Main {
public static class Unused {};
public interface BaseClass<T> {
Long pie();
}
public static class ChildImpl implements BaseClass<Unused> {
@Override
public Long pie() { return 3L; }
}
public static void main(String args[]) {
BaseClass myObject = new ChildImpl();
Long piece = myObject.pie();
}
}
Run Code Online (Sandbox Code Playgroud)
但是为什么以下不能编译?
import java.util.Collections;
import java.util.List;
public class Main {
public static class Unused{};
public interface BaseClass<T> {
List<Long> pie();
}
public …Run Code Online (Sandbox Code Playgroud) 我为我们的 Java 程序分配了 2GB 内存。在特定线程运行的时间内,内存会稳定且线性地增加,直到 Kubernetes 将其杀死,因为它达到了我分配的 2GB 限制。当然,我们正在考虑内存泄漏,但我们总是在 gc 日志中看到这样的内容:
[7406.381s][info][gc] GC(8326) Pause Full (System.gc()) 130M->65M(214M) 157.995ms
Run Code Online (Sandbox Code Playgroud)
一些背景信息:
没有日志表明容器已被停止或终止。k8s 中也没有事件(但是“重新启动”= 1)。上面的日志行是我们(在 Graylog 中)看到 Spring Boot / Tomcat 正在启动之前的最后一个日志行(因此它必须已重新启动)。我们看到这种情况恰好发生在 Grafana 中内存图达到 2GB 线时。如果没有 Grafana,我们可能需要一段时间才能弄清楚这是与内存相关的东西。
Kubernetes部署yml部分:
spec:
template:
spec:
containers:
- name: ... (omitted)
resources:
limits:
cpu: 1200m
memory: 2Gi
requests:
cpu: 50m
memory: 50Mi
Run Code Online (Sandbox Code Playgroud)
Dockerfile 的最后一行:
ENTRYPOINT ["java", "-Xmx2G", "-verbose:gc", "-jar", "/backend.jar"]
Run Code Online (Sandbox Code Playgroud)
其中“-verbose:gc”导致日志行类似于我上面引用的行。
重现该问题需要一段时间,但我们已经这样做了几次。
我们正在使用 Java 11。
java ×7
c++ ×2
algorithm ×1
apache-karaf ×1
avx ×1
deprecated ×1
docker ×1
eclipse ×1
fastapi ×1
grafana ×1
include ×1
jaxb ×1
kubernetes ×1
libs ×1
math ×1
maven ×1
memory-leaks ×1
mingw ×1
mockito ×1
osgi ×1
osgi-bundle ×1
pom.xml ×1
primes ×1
project-loom ×1
python ×1
rounding ×1
simd ×1
w3c ×1
windows ×1