我正在使用javanica并注释我的hystrix命令方法,如下所示:
@HystrixCommand(groupKey="MY_GROUP", commandKey="MY_COMMAND" fallbackMethod="fallbackMethod")
public Object getSomething(Object request) {
....
Run Code Online (Sandbox Code Playgroud)
我试图对我的回退方法进行单元测试,而不必直接调用它们,即我想调用带@HystrixCommand注释的方法,并在抛出500错误后让它自然地流入回退.这一切都在单元测试之外工作.
在我的单元测试中,我使用弹簧MockRestServiceServer返回500个错误,这部分正在工作,但Hystrix没有在我的单元测试中正确初始化.在我的测试方法开始时,我有:
HystrixRequestContext context = HystrixRequestContext.initializeContext();
myService.myHystrixCommandAnnotatedMethod();
Run Code Online (Sandbox Code Playgroud)
在此之后,我试图通过键获取任何hystrix命令并检查是否有任何已执行的命令,但列表始终为空,我使用此方法:
public static HystrixInvokableInfo<?> getHystrixCommandByKey(String key) {
HystrixInvokableInfo<?> hystrixCommand = null;
System.out.println("Current request is " + HystrixRequestLog.getCurrentRequest());
Collection<HystrixInvokableInfo<?>> executedCommands = HystrixRequestLog.getCurrentRequest()
.getAllExecutedCommands();
for (HystrixInvokableInfo<?> command : executedCommands) {
System.out.println("executed command is " + command.getCommandGroup().name());
if (command.getCommandKey().name().equals(key)) {
hystrixCommand = command;
break;
}
}
return hystrixCommand;
}
Run Code Online (Sandbox Code Playgroud)
我意识到我在单元测试初始化中遗漏了一些东西,任何人都可以指出我正确的方向如何正确地进行单元测试吗?
我在一个视图中创建了两个操作表.有两个按钮,每个按钮将启动一个操作表.
问题:当我在两个操作表中按下第一个选项时,会触发相同的操作.
这是我的代码:
-(IBAction) ChangeArrow:(id)sender{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Change Arrow"
delegate:self
cancelButtonTitle:@"cancel"
destructiveButtonTitle:@"Red"
otherButtonTitles:@"Blue",@"Black",nil];
[actionSheet showInView:self.view];
[actionSheet release];}
- (void) actionSheet: (UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex ==[actionSheet destructiveButtonIndex]) {
self.bar.image=[UIImage imageNamed:@"red"];
}
else if(buttonIndex == 1){
self.bar.image=[UIImage imageNamed:@"blue"];
}
else if(buttonIndex == 2){
self.bar.image=[UIImage imageNamed:@"dark"];}
}
Run Code Online (Sandbox Code Playgroud)
//第二个行动表:
-(IBAction) Background:(id)sender{
UIActionSheet *actionSheet2 = [[UIActionSheet alloc] initWithTitle:@"Change Background"
delegate:self
cancelButtonTitle:@"cancel"
destructiveButtonTitle:@"Sky"
otherButtonTitles:@"Thumbs",@"Smiley",nil];
[actionSheet2 showInView:self.view];
[actionSheet2 release];
}
- (void) actionSheet2: (UIActionSheet *)actionSheet2 didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex ==[actionSheet2 destructiveButtonIndex]) {
self.background.image=[UIImage …Run Code Online (Sandbox Code Playgroud) 我想使用Hibernate的过滤器来过滤"MyEntity"对象,在过滤条件中使用"AnotherEntity"选项.配置看起来像这样:
<hibernate-mapping>
<filter-def name="myFilter" condition="someProperty in (select x.property1 from AnotherEntity x where property2 = :property2)">
<filter-param name="property2" type="long"/>
</filter-def>
<class name="com.example.MyEntity" table="SOME_TABLE">
<id name="OID" column="O_ID" type="long">
<generator class="hilo">
<param name="table">oid_id</param>
<param name="column">next_id</param>
</generator>
</id>
<version name="hibernateVersion" column="hibernate_version" unsaved-value="negative"/>
<property name="someProperty"/>
<filter name="myFilter"/>
</class>
<class name="com.example.AnotherEntity" table="ANOTHER_TABLE">
<composite-id>
<key-many-to-one name="property1" ... />
<key-many-to-one name="property2" ... />
</composite-id>
</class>
</hibernate-mapping>
Run Code Online (Sandbox Code Playgroud)
这给了我一个org.hibernate.exception.SQLGrammarException: could not execute querySQLException Table "ANOTHERENTITY" not found,因为生成的SQL语句包含"AnotherEntity"而不是映射表"ANOTHER_TABLE",好像没有找到映射一样.但是,当我执行subselect时
select x.property1 from AnotherEntity x where property2 = :property2
Run Code Online (Sandbox Code Playgroud)
它只是工作正常. …
我尝试在Mac OSX上从Java访问网络文件夹/ UNC路径.在Windows上,以下测试程序正常工作(至少有一个测试路径):
public class PathTest {
public static void main(String[] args) {
for (String path : Arrays.asList(
"\\\\myserver\\transfer", "//myserver/transfer", "file://myserver/transfer", "smb://myserver/transfer")) {
File f = new File(path);
System.out.println(path + ": " + f.getAbsolutePath() + ", " + f.exists());
Path p = Paths.get(path);
System.out.println(path + ": " + p.toAbsolutePath() + ", " + Files.exists(p));
}
}
}
Run Code Online (Sandbox Code Playgroud)
在Mac OS上它无法访问文件夹:
\\myserver\transfer: /Users/tim/IdeaProjects/PathTest/\\myserver\transfer, false
//myserver/transfer: /myserver/transfer, false
file://myserver/transfer: /Users/tim/IdeaProjects/PathTest/file://myserver/transfer, false
smb://myserver/transfer: /Users/tim/IdeaProjects/PathTest/smb://myserver/transfer, false
Run Code Online (Sandbox Code Playgroud)
当我使用Finder时,我可以使用"smb:// myserver/transfer"访问文件夹(使用Guest用户).怎么了?
编辑添加了NIO.2测试
我想知道为什么Java Collections API不包含map不同集合类型的方便方法.我想写一些类似的东西:
List<Foo> list = ...;
List<String> result = list.map(Foo::toString);
Run Code Online (Sandbox Code Playgroud)
相反,我必须创建一个流,地图和收集,如下所示:
List<Foo> list = ...;
List<String> result = list.stream().map(Foo::toString).collect(toList());
Run Code Online (Sandbox Code Playgroud)
难道不像在java.util.List接口中实现这个默认方法那么容易吗?例如
default <R> List<R> map(Function<E, R> mapper){
return stream().map(mapper).collect(Collectors.toList());
}
Run Code Online (Sandbox Code Playgroud)
乍一看,似乎有其他方便的方法.例如:
list.stream().forEach(x -> {});
Run Code Online (Sandbox Code Playgroud)
可写成
list.forEach(x -> {});
Run Code Online (Sandbox Code Playgroud)
但是,比较并不是那么好.Iteratable.forEach是顶级接口上的默认方法,不需要指定返回类型.它不是在引擎盖下创建一个流,而是使用Iteratables属性来......好......迭代所有元素.
所以问题仍然存在:为什么不在每个Collections API接口上都有map方法?也许是因为它不够灵活,因为你需要决定一个返回类型?
我确信实现者已经考虑过它,并且有理由不把它放进去.我想了解原因.
我正在构建一个使用 OpenId 来验证用户身份的 Web 应用程序,就像 Stackoverlfow 所做的那样。也会有一个移动应用程序,例如 Android 或 iPhone。这些应用程序必须以某种方式进行身份验证或登录,才能访问数据并更新属于用户的内容。由于无法提供用户名和密码来验证移动设备,我想知道如何实现这一点。
我想到了两种方法:
在服务器上生成一些必须在设备上输入的密钥。当移动设备发送或请求数据时,该密钥将作为身份验证密钥发送,并且可以通过这种方式链接用户。使用此选项时,密钥应以某种方式传输给用户,这样他就不必输入密钥。可能通过电子邮件、短信或扫描条形码。
移动应用程序使用浏览器或显示一个集成的 Web 面板,该面板可打开 Web 应用程序的特殊页面。在此页面上,用户必须登录,然后才能允许移动应用程序读取和写入数据。
我的问题是:这两种方法都可行且安全吗?您更喜欢哪一个?有哪些细节需要注意?还有其他方法可以做到这一点吗?如果我没问题的话,就不可能在设备上使用 OpenId,并以这种方式链接移动设备和 web 应用程序,对吧?
我尝试使用带有PagingNavigation的PageableListView.从看起来很容易的例子,但我无法让它工作.我总是收到以下错误消息:
下面的组件无法呈现.一个常见问题是您在代码中添加了一个组件,但忘记在标记中引用它
这是我的java代码:
class FriendsPanel extends Panel {
public FriendsPanel(String id){
super(id);
List<User> friends = ...;
PageableListView<User> listview = new PageableListView<User>("listview", friends, 10) {
protected void populateItem(ListItem<User> item) {
User user = item.getModel().getObject();
item.add(new Label("label", user.getName()));
}
};
add(listview);
add(new PagingNavigation("navigator", listview));
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的HTML看起来像这样:
<html xmlns:wicket>
<wicket:panel>
<br />
<span wicket:id="listview">
<span wicket:id="label">label</span><br>
</span>
<div wicket:id="navigator"></div>
</wicket:panel>
</html>
Run Code Online (Sandbox Code Playgroud)
任何想法如何使这项工作?
我想突出显示一个带有背景颜色的选择元素,这是强制性的.当用户通过单击打开菜单时,我想删除背景颜色,因此它看起来更好,更具可读性.这在Firefox,Chrome甚至IE6中都可以正常工作,但在IE7和8上,下拉时不会打开下拉(或者打开和关闭非常快),仅在第二次打开时.
<select
style="background-color: #BDE5F8"
onfocus="this.style.backgroundColor='#fff'"
onblur="this.style.backgroundColor='#BDE5F8'">
<option>choose...</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
在我的Android应用程序中,我正在尝试显示德语文本.öäüß这些角色无法显示TextView.如果有人知道如何设置字体或如何显示字符让我知道.我从服务中收到的数据.
java ×3
android ×2
iphone ×2
annotations ×1
collections ×1
css ×1
diacritics ×1
hibernate ×1
hql ×1
html ×1
hystrix ×1
java-stream ×1
javascript ×1
macos ×1
mobile ×1
unicode ×1
unit-testing ×1
wicket ×1