小编Hum*_*mad的帖子

SpringJUnit4ClassRunner和SpringRunner有什么区别

每当我看到一篇与Spring测试相关的博客文章时,我都会看到这些类中的任何一个,但却不了解真正的区别:

@RunWith(SpringRunner.class)
@RunWith(SpringJUnit4ClassRunner.class)
Run Code Online (Sandbox Code Playgroud)

java spring unit-testing spring-test

74
推荐指数
2
解决办法
2万
查看次数

Selenium:Runtime.executionContextCreated具有无效的'context':

我在这里看了类似的问题Protractor/Selenium Webdriver:Runtime.executionContextCreated有无效的'context'BUG-1473,但我无法得到答案因此我决定在这里给它.我安装了最新的chrome_driver v2.9,但仍然Runtime.executionContextCreated出错.这是我的代码

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('http://www.google.com/xhtml')
Run Code Online (Sandbox Code Playgroud)

并在python shell上抛出异常:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/humoyun/Documents/virtual_env_fold/flasky/fl_venv/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 248, in get
    self.execute(Command.GET, {'url': url})
  File "/Users/humoyun/Documents/virtual_env_fold/flasky/fl_venv/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "/Users/humoyun/Documents/virtual_env_fold/flasky/fl_venv/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"2061.1","isDefault":true},"id":1,"name":"","origin":"://"}
  (Session info: chrome=55.0.2883.95)
  (Driver info: chromedriver=2.9.248307,platform=Mac OS X 10.11.3 x86_64)
Run Code Online (Sandbox Code Playgroud)

python macos selenium automated-tests chrome-web-driver

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

两个Google JS客户端:platform.js和api.js有什么区别?

A) <script src="https://apis.google.com/js/platform.js"></script>
Run Code Online (Sandbox Code Playgroud)

B) <script src="https://apis.google.com/js/api.js"></script>
Run Code Online (Sandbox Code Playgroud)

我应该使用平台脚本还是api脚本,对如何使用Google OAuth服务有些困惑。

javascript oauth-2.0 google-oauth2

9
推荐指数
1
解决办法
412
查看次数

与System.out关联的Java线程的奇怪行为

我有一个简单的TestThreadClientMode类来测试竞争条件.我尝试了两次尝试:

  1. 当我System.out.println(count);在第二个线程中使用注释运行以下代码时,输出为:

OS: Windows 8.1 flag done set true ...

第二个线程永远活着.因为第二个线程永远不会看到done由主线程设置为true 的标志的更改.

  1. 当我取消注释System.out.println(count);输出时:

    OS: Windows 8.1 0 ... 190785 190786 flag done set true Done! Thread-0 true

程序在1秒后停止.

怎么System.out.println(count);让第二个线程看到变化done

public class TestThreadClientMode {
    private static boolean done;
    public static void main(String[] args) throws InterruptedException {
        new Thread(new Runnable() {
            public void run() {
                int count = 0;
                while (!done) {
                    count ++;
                    //System.out.println(count);
                }
                System.out.println("Done! " + …
Run Code Online (Sandbox Code Playgroud)

java multithreading race-condition

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

如何在 Hapi.js 中正确注册插件

我关注了hapi的官网,尝试了一个简单的服务器,但是失败了:我无法注册插件,

var Hapi = require('hapi');

var server = new Hapi.Server();

server.connection({port: 4004});

server.register([require('inert'), require('vision')], (err) => {
    if (err) {
        throw err;
    }

    server.start(err => {
        console.log('server started');
    });
});
Run Code Online (Sandbox Code Playgroud)

它正在抛出愚蠢的错误:

/Users/apple/Documents/node_projects/hapijon/testjon/ch4_routes_and_handlers/node_modules/hapi/lib/plugin.js:219
        if (plugin.register.register) {                             // Required plugin
                            ^

TypeError: Cannot read property 'register' of undefined
    at module.exports.internals.Server.internals.Plugin.register (/Users/apple/Documents/node_projects/hapijon/testjon/ch4_routes_and_handlers/node_modules/hapi/lib/plugin.js:219:29)
    at Object.<anonymous> (/Users/apple/Documents/node_projects/hapijon/testjon/ch4_routes_and_handlers/tess.js:7:8)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
Run Code Online (Sandbox Code Playgroud)

这是我的 package.json:

  "dependencies": {
    "accept": …
Run Code Online (Sandbox Code Playgroud)

javascript plugins node.js hapijs

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

如何在Windows中的自定义协议处理程序中转义和号

我在此链接之后创建了一个自定义协议处理程序。情况是我需要打开一个链接,该链接只能在IE中打开,并且可能包含多个查询参数,应该从运行在Chrome上的Web应用程序在IE中打开该链接(这确实很烦人)。经过多次尝试和失败之后,我设法找到了将代码段添加到Windows注册表配置单元中的代码片段,并制作了.reg文件并运行:

Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\ie]
"URL Protocol"="\"\""
@="\"URL:IE Protocol\""
[HKEY_CURRENT_USER\Software\Classes\ie\DefaultIcon]
@="\"explorer.exe,1\""
[HKEY_CURRENT_USER\Software\Classes\ie\shell]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open\command]
@="cmd /k set myvar=%1 & call set myvar=%%myvar:ie:=%% & call \"C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe\" %%myvar%% & exit /B"
Run Code Online (Sandbox Code Playgroud)

它起作用了,但问题是,如果链接包含多个查询参数,则除第一个以外的所有查询参数都将被省略,我确信这是因为Windows命令行中的字符编码:

e.g. some_example_url?query1=value1&query2=value2&query3=value3 is becoming some_example_url?query1=value1
Run Code Online (Sandbox Code Playgroud)

我找到了这个解决方案,但它也不起作用。如何正确转义&字符,以便可以在IE中使用所有查询参数打开字符。(如前所述,链接是由运行在Chrome上的网络应用触发的)

编辑:触发​​以下代码:

fileClicked(url) {
  // url should be escaped with ^
  const escapedUrl = url.replace(/&/gi, '^&');
  const ie = document.createElement('a');
  // ie: scheme => custom protocol handler …
Run Code Online (Sandbox Code Playgroud)

windows internet-explorer command-line google-chrome protocol-handler

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

如何将可选字段(Java 8 API)更改为Java 7

我有一个来自Github的应用程序,其中使用了Java 8 API,即Optional关键字。但是我想运行该应用程序的环境设置为JDK_7。因此,由于我对Java 8 API的使用经验为零,因此谁能提供以下示例代码的替代代码块:

public final static Optional<String> reverseGeocodeFromLatLong(final double latitude, final double longitude) {
    final StringBuilder bingMapsURL = new StringBuilder();
    bingMapsURL
            .append(BING_MAPS_URL_START)
            .append(latitude)
            .append(",")
            .append(longitude)
            .append(BING_MAPS_URL_MIDDLE_JSON)
            .append(Constants.BING_MAPS_API_KEY_VALUE);
    LOGGER.debug("BingMapsURL==>{}", bingMapsURL.toString());

    HttpURLConnection httpURLConnection;
    InputStream inputStream = null;
    try {
        final URL url = new URL(bingMapsURL.toString());
        httpURLConnection = (HttpURLConnection)url.openConnection();

        if(HttpURLConnection.HTTP_OK == httpURLConnection.getResponseCode()){
            inputStream = httpURLConnection.getInputStream();
            return getStateFromJSONResponse(inputStream);
        }
    } catch (final Throwable throwable) {
        LOGGER.error(throwable.getMessage(), throwable);
        throwable.printStackTrace();
    } finally{
        if(null != inputStream) {
            try {
                inputStream.close();
            } catch (final IOException ioException) …
Run Code Online (Sandbox Code Playgroud)

java optional java-8

4
推荐指数
1
解决办法
3656
查看次数

Disruptor - Ring Buffer

我正在调查LMAX Disruptor的源代码,我进入了RingBuffer抽象类.为什么正好有7个长场(p1 ... p7)RingBufferPad?这是实际代码:https: //github.com/LMAX-Exchange/disruptor/blob/master/src/main/java/com/lmax/disruptor/RingBuffer.java

abstract class RingBufferPad
{
    protected long p1, p2, p3, p4, p5, p6, p7;
}

abstract class RingBufferFields<E> extends RingBufferPad
{
....
Run Code Online (Sandbox Code Playgroud)

java circular-buffer data-structures disruptor-pattern

4
推荐指数
1
解决办法
342
查看次数

无法理解装饰模式的主要缺点

我正在学习Decorator Pattern.它是非常强大的模式,非常有用.模式的目标很简单,在运行时向对象添加(扩展)行为,而无需通过组合和委托重新编译源代码,因此为扩展行为提供了子类化的替代方法.但是,我读到了这种模式的一个主要缺点,并不能完全理解它.这是声明:

"人们有时会采用一段依赖于特定类型的客户端代码,并在不考虑所有内容的情况下引入装饰器.现在,关于我的一件好事是,你通常可以透明地插入装饰器,而客户端永远不必知道它正在处理装饰器.但就像我说的那样,一些代码依赖于特定的类型,当你开始介绍装饰时,繁荣!糟糕的事情发生了."

取自"头首设计模式"

作者的意思是"依赖于特定类型".如果可能的话,请用现实世界和简单的例子

design-patterns decorator

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

Storm中的任务ID与消息ID与流ID的区别?"锚定元组"和"acker任务"如何与上下文相关?

我想知道它们之间的区别,以及它们如何相互关联,以及"锚定元组"和"acker任务"的作用是什么.如果可能,请提供详细的说明和示例.我已经阅读了官方文档和一些相关文章,但我对这个主题的理解还不清楚.

apache-storm

2
推荐指数
1
解决办法
1615
查看次数