我的问题是这一个的变种.
由于我的Java Web应用程序项目需要大量读取过滤器/查询以及与GridFS等工具的接口,因此我很难想到以上述解决方案建议的方式使用MongoDB的合理方法.
因此,我正在考虑在我的集成测试中运行MongoDB的嵌入式实例.我希望它能自动启动(对于每个测试或整个套件),为每个测试刷新数据库,最后关闭.这些测试可能在开发机器和CI服务器上运行,因此我的解决方案也需要是可移植的.
任何对MongoDB有更多了解的人都能帮助我了解这种方法的可行性,并且/或者建议任何可能帮助我入门的阅读材料吗?
我也对人们对如何处理这个问题的其他建议持开放态度......
我正在编写一个Java项目,在编译时发出以下警告:
/src/com/myco/apps/AppDBCore.java:439: warning: unmappable character for encoding UTF8
[javac] String copyright = "? 2003-2008 My Company. All rights reserved.";
Run Code Online (Sandbox Code Playgroud)
我不确定SO会如何在日期之前渲染角色,但它应该是版权符号,并在警告中显示为钻石中的问号.
值得注意的是,角色正确地出现在输出工件中,但警告是令人讨厌的,包含此类的文件可能有一天会被文本编辑器触及,这会错误地保存编码...
如何将此字符注入"copyright"字符串,以便编译器满意,并且该符号保留在文件中而没有潜在的重新编码问题?
如何从当前光标行中删除文本块到vi中的给定行号?
例如:
49 <j:set var="changeSet" value="${build.changeSet}" /> <----- delete from here (cursor position)
50 <j:if test="${changeSet!=null}">
51 <j:set var="hadChanges" value="false" />
52 <TABLE width="100%">
53 <TR><TD class="bg1" colspan="2"><B>CHANGES</B></TD></TR>
54 <j:forEach var="cs" items="${changeSet.logs}" varStatus="loop">
55 <j:set var="hadChanges" value="true" />
56 <j:set var="aUser" value="${cs.hudsonUser}"/>
57 <TR>
58 <TD colspan="2" class="bg2">${spc}Revision <B>${cs.revision}</B> by
59 <B><j:choose>
60 <j:when test="${aUser!=null}">${aUser.displayName}: </j:when>
61 <j:otherwise>${cs.user}: </j:otherwise>
62 </j:choose></B>
63 <B>(${cs.msgAnnotated})</B> <----- to here (line 63)
64 </TD>
65 </TR>
66 <j:forEach var="p" items="${cs.paths}">
67 <TR>
68 <TD …Run Code Online (Sandbox Code Playgroud) 我正在尝试在项目中使用子类的typedef,我在下面的示例中已经分离了我的问题.
有谁知道我哪里出错了?
template<typename Subclass>
class A {
public:
//Why doesn't it like this?
void action(typename Subclass::mytype var) {
(static_cast<Subclass*>(this))->do_action(var);
}
};
class B : public A<B> {
public:
typedef int mytype;
B() {}
void do_action(mytype var) {
// Do stuff
}
};
int main(int argc, char** argv) {
B myInstance;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出:
sean@SEAN-PC:~/Documents/LucadeStudios/experiments$ g++ -o test test.cpp
test.cpp: In instantiation of ‘A<B>’:
test.cpp:10: instantiated from here
test.cpp:5: error: invalid use of incomplete type ‘class B’
test.cpp:10: error: forward …Run Code Online (Sandbox Code Playgroud) 我在将扩展对象作为参数传递给函数时尝试使用抽象类,但到目前为止,我的尝试导致了一些编译器错误.
关于问题是什么,我有一些线索,我显然不允许实例化一个抽象类,我相信MyClass中的一些代码试图这样做,即使这不是我的意图.一些研究表明我应该将对象作为指针来实现我想要的东西,但到目前为止我的尝试都失败了,我甚至不确定这是答案(因此我的问题在这里).
我现在提交我比Java更熟悉Java,我确信我的部分问题是由于这个原因.
这是我在我的程序中尝试做的一个例子:
class A {
public:
virtual void action() = 0;
};
class B : public A {
public:
B() {}
void action() {
// Do stuff
}
};
class MyClass {
public:
void setInstance(A newInstance) {
instance = newInstance;
}
void doSomething() {
instance.action();
}
private:
A instance;
};
int main(int argc, char** argv) {
MyClass c;
B myInstance;
c.setInstance(myInstance);
c.doSomething();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
此示例产生与我在程序中获得的相同的编译器错误:
sean@SEAN-PC:~/Desktop$ gcc -o test test.cpp
test.cpp:20: error: cannot declare parameter ‘newInstance’ to …Run Code Online (Sandbox Code Playgroud) 当使用Apache Jersey与Jackson进行JSON序列化(在服务器和客户端上)时,我在反序列化通用List时遇到了问题.
我生成的JSON如下,"data"中的所有3个类都实现了"CheckStatusDetail":
{
"errorCode" : 0,
"errorMessage" : null,
"type" : "array",
"data" : [ {
"@class" : "com.rrr.base.status.module.dto.DiscoveryAgentCheckStatusDetail",
"serverInfo" : {
"@class" : "com.rrr.base.util.discovery.config.xml.XMLServerInfo",
"name" : "java",
"location" : "THEO",
"description" : "sddgs",
"group" : "java",
"aliases" : [ "mercury" ]
}
}, {
"@class" : "com.rrr.base.status.module.dto.MongoDBCheckStatusDetail",
"addresses" : [ "localhost:27017" ],
"version" : "2.5",
"connected" : true
}, {
"@class" : "com.rrr.base.status.module.dto.NetworkCheckStatusDetail",
"splitBrain" : false
} ],
"count" : 3,
"status" : 0
}
Run Code Online (Sandbox Code Playgroud)
生成此JSON的对象看起来像这样,我在客户端使用相同的类:
public class …Run Code Online (Sandbox Code Playgroud) 我有一个自我执行的jar程序,它很大程度上依赖于Spring Integration.我遇到的问题是程序在其他Spring bean完成之前终止.
下面是我正在使用的代码的简化版本,如果需要,我可以提供更多代码/配置.入口点是一个main()方法,它引导Spring并启动导入过程:
public static void main(String[] args) {
ctx = new ClassPathXmlApplicationContext("flow.xml");
DataImporter importer = (DataImporter)ctx.getBean("MyImporterBean");
try {
importer.startImport();
} catch (Exception e) {
e.printStackTrace();
} finally {
ctx.close();
}
}
Run Code Online (Sandbox Code Playgroud)
DataImporter包含一个简单的循环,用于将消息发送到Spring Integration网关.这为流程提供了一种主动的"推送"方法,而不是轮询数据的常用方法.这是我的问题所在:
public void startImport() throws Exception {
for (Item item : items) {
gatewayBean.publish(item);
Thread.sleep(200); // Yield period
}
}
Run Code Online (Sandbox Code Playgroud)
为了完整起见,流XML看起来像这样:
<gateway default-request-channel="inChannel" service-interface="GatewayBean" />
<splitter input-channel="inChannel" output-channel="splitChannel" />
<payload-type-router input-channel="splitChannel">
<mapping type="Item" channel="itemChannel" />
<mapping type="SomeOtherItem" channel="anotherChannel" />
</payload-type-router>
<outbound-channel-adapter channel="itemChannel" ref="DAOBean" method="persist" …Run Code Online (Sandbox Code Playgroud) (标题是:"如何为用Python编写的DBUS服务编写单元测试?")
我已经开始使用dbus-python编写DBUS服务,但是我在编写测试用例时遇到了麻烦.
这是我正在尝试创建的测试示例.请注意,我在setUp()中放置了一个GLib事件循环,这就是问题所在:
import unittest
import gobject
import dbus
import dbus.service
import dbus.glib
class MyDBUSService(dbus.service.Object):
def __init__(self):
bus_name = dbus.service.BusName('test.helloservice', bus = dbus.SessionBus())
dbus.service.Object.__init__(self, bus_name, '/test/helloservice')
@dbus.service.method('test.helloservice')
def hello(self):
return "Hello World!"
class BaseTestCase(unittest.TestCase):
def setUp(self):
myservice = MyDBUSService()
loop = gobject.MainLoop()
loop.run()
# === Test blocks here ===
def testHelloService(self):
bus = dbus.SessionBus()
helloservice = bus.get_object('test.helloservice', '/test/helloservice')
hello = helloservice.get_dbus_method('hello', 'test.helloservice')
assert hello() == "Hello World!"
if __name__ == '__main__':
unittest.main()
Run Code Online (Sandbox Code Playgroud)
我的问题是DBUS实现要求您启动一个事件循环,以便它可以开始调度事件.常见的方法是使用GLib的gobject.MainLoop().start()(虽然我没有嫁给这种方法,如果有人有更好的建议).如果您没有启动事件循环,该服务仍会阻止,您也无法查询它.
如果我在测试中启动我的服务,事件循环会阻止测试完成.我知道该服务正在运行,因为我可以使用qdbus工具从外部查询服务,但我无法在启动它的测试中自动执行此操作.
我正在考虑在测试中进行某种处理以处理这个问题,但我希望有人可能有一个更整洁的解决方案,或者至少是一个很好的起点,我将如何编写这样的测试.
我正在尝试在JUnit测试中使用使用Apache CXF的HTTP基本身份验证的远程Web服务.
我得到的错误是:
javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://localhost:8080/services/MyService?wsdl. It failed with:
Server returned HTTP response code: 401 for URL: http://localhost:8080/services/MyService?wsdl.
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:151)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:133)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:254)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:217)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:165)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)
at javax.xml.ws.Service.<init>(Service.java:76)
at com.wave2.marketplace.importer.impl.adportal.ws.MyServiceService.<init>(MyServiceService.java:37)
at com.wave2.marketplace.importer.impl.adportal.MyWSTest.testConsumingTheWS(MyWSTest.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种在webapp中检索Tomcat日志的方法.在过去,我已经看到其他webapps中提供的这个功能,通常将日志转储到Servlet中.
我正在使用slf4j(使用log4j)和Tomcat 6.我没有在Tomcat文档中找到任何相关内容,尽管JMX API看起来可能提供了一些有用的东西?我不太关心输出是仅代表webapp日志记录还是整个Tomcat日志,要么就足够了.
理想情况下,我希望找到一个不涉及从文件系统中抓取日志的解决方案,尽管如果这是唯一的方法,如果可以在运行时计算日志目录,那将会很棒...