当前位置: 首页>>代码示例>>Java>>正文


Java Runnable类代码示例

本文整理汇总了Java中com.github.dreamhead.moco.Runnable的典型用法代码示例。如果您正苦于以下问题:Java Runnable类的具体用法?Java Runnable怎么用?Java Runnable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Runnable类属于com.github.dreamhead.moco包,在下文中一共展示了Runnable类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: should_bootstrap

import com.github.dreamhead.moco.Runnable; //导入依赖的package包/类
@Test
public void should_bootstrap() throws Exception {
    final HttpServer server = httpserver(12306);
    server.get(by(uri("/classpath"))).response("http://localhost:12306/jar/test.jar");
    server.get(by(uri("/jar/test.jar")))
          .response(header("Content-Type", "application/java-archive"),
                    content(file("target/stub-tests.jar")));

    running(server, new Runnable() {
        @Override
        public void run() throws Exception {
            final Instrumentation inst = mock(Instrumentation.class);
            Lurker.bootstrap("http://localhost:12306/classpath?bootstrap=me.zhongl.stub.Bootstrap&k=v", inst);
            Lurker.bootstrap("http://localhost:12306/classpath?bootstrap=me.zhongl.stub.SimpleAgent", inst);
            Lurker.bootstrap("http://localhost:12306/classpath?bootstrap=me.zhongl.stub.ConfigurableAgent&k=v", inst);
            Lurker.bootstrap("http://localhost:12306/classpath?bootstrap=me.zhongl.stub.InstrumentationAgent", inst);
            Lurker.bootstrap("http://localhost:12306/classpath?bootstrap=me.zhongl.stub.SuperAgent&k=v", inst);
        }
    });
}
 
开发者ID:zhongl,项目名称:lurker,代码行数:21,代码来源:LurkerTest.java

示例2: should_get_classpath_urls_event_if_redirected

import com.github.dreamhead.moco.Runnable; //导入依赖的package包/类
@Test
public void should_get_classpath_urls_event_if_redirected() throws Exception {
    final String redirect = "/real/classpath";
    final String content = "http://localhost:12306/jar/test.jar";

    final HttpServer server = httpserver(12306);
    server.get(by(uri("/classpath"))).redirectTo(redirect);
    server.get(by(uri(redirect))).response(content);

    running(server, new Runnable() {
        @Override
        public void run() throws Exception {
            final URL[] urls = Lurker.urls("http://localhost:12306/classpath");
            assertThat(urls.length, is(1));
            assertThat(urls[0], is(new URL(content)));
        }
    });
}
 
开发者ID:zhongl,项目名称:lurker,代码行数:19,代码来源:LurkerTest.java

示例3: should_complain_invalid_url

import com.github.dreamhead.moco.Runnable; //导入依赖的package包/类
@Test
public void should_complain_invalid_url() throws Exception {
    final String content = "ttp://localhost:12306/jar/test.jar";

    final HttpServer server = httpserver(12306);
    server.get(by(uri("/classpath"))).response(content);

    running(server, new Runnable() {
        @Override
        public void run() throws Exception {

            try {
                Lurker.urls("http://localhost:12306/classpath");
                fail();
            } catch (IllegalStateException ignored) { }
        }
    });
}
 
开发者ID:zhongl,项目名称:lurker,代码行数:19,代码来源:LurkerTest.java

示例4: test_set_request_cookie

import com.github.dreamhead.moco.Runnable; //导入依赖的package包/类
@Test
public void test_set_request_cookie() throws Exception {
    HttpServer server = httpServer(13423);
    server.get(eq(cookie("cookie"), "cookie-webmagic")).response("ok");
    Runner.running(server, new Runnable() {
        @Override
        public void run() throws Exception {
            HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
            Request request = new Request();
            request.setUrl("http://127.0.0.1:13423");
            request.addCookie("cookie","cookie-webmagic");
            Page page = httpClientDownloader.download(request, Site.me().toTask());
            assertThat(page.getRawText()).isEqualTo("ok");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:17,代码来源:HttpClientDownloaderTest.java

示例5: test_disableCookieManagement

import com.github.dreamhead.moco.Runnable; //导入依赖的package包/类
@Test
public void test_disableCookieManagement() throws Exception {
    HttpServer server = httpServer(13423);
    server.get(not(eq(cookie("cookie"), "cookie-webmagic"))).response("ok");
    Runner.running(server, new Runnable() {
        @Override
        public void run() throws Exception {
            HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
            Request request = new Request();
            request.setUrl("http://127.0.0.1:13423");
            request.addCookie("cookie","cookie-webmagic");
            Page page = httpClientDownloader.download(request, Site.me().setDisableCookieManagement(true).toTask());
            assertThat(page.getRawText()).isEqualTo("ok");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:17,代码来源:HttpClientDownloaderTest.java

示例6: test_set_request_header

import com.github.dreamhead.moco.Runnable; //导入依赖的package包/类
@Test
public void test_set_request_header() throws Exception {
    HttpServer server = httpServer(13423);
    server.get(eq(header("header"), "header-webmagic")).response("ok");
    Runner.running(server, new Runnable() {
        @Override
        public void run() throws Exception {
            HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
            Request request = new Request();
            request.setUrl("http://127.0.0.1:13423");
            request.addHeader("header","header-webmagic");
            Page page = httpClientDownloader.download(request, Site.me().toTask());
            assertThat(page.getRawText()).isEqualTo("ok");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:17,代码来源:HttpClientDownloaderTest.java

示例7: test_set_site_cookie

import com.github.dreamhead.moco.Runnable; //导入依赖的package包/类
@Test
public void test_set_site_cookie() throws Exception {
    HttpServer server = httpServer(13423);
    server.get(eq(cookie("cookie"), "cookie-webmagic")).response("ok");
    Runner.running(server, new Runnable() {
        @Override
        public void run() throws Exception {
            HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
            Request request = new Request();
            request.setUrl("http://127.0.0.1:13423");
            Site site = Site.me().addCookie("cookie", "cookie-webmagic").setDomain("127.0.0.1");
            Page page = httpClientDownloader.download(request, site.toTask());
            assertThat(page.getRawText()).isEqualTo("ok");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:17,代码来源:HttpClientDownloaderTest.java

示例8: test_download_auth_by_SimpleProxyProvider

import com.github.dreamhead.moco.Runnable; //导入依赖的package包/类
@Test
public void test_download_auth_by_SimpleProxyProvider() throws Exception {
    HttpServer server = httpServer(13423);
    server.get(eq(header("Proxy-Authorization"), "Basic dXNlcm5hbWU6cGFzc3dvcmQ=")).response("ok");
    Runner.running(server, new Runnable() {
        @Override
        public void run() throws Exception {
            HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
            httpClientDownloader.setProxyProvider(SimpleProxyProvider.from(new Proxy("127.0.0.1", 13423, "username", "password")));
            Request request = new Request();
            request.setUrl("http://www.baidu.com");
            Page page = httpClientDownloader.download(request, Site.me().toTask());
            assertThat(page.getRawText()).isEqualTo("ok");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:17,代码来源:HttpClientDownloaderTest.java

示例9: test_download_binary_content

import com.github.dreamhead.moco.Runnable; //导入依赖的package包/类
@Test
public void test_download_binary_content() throws Exception {
    HttpServer server = httpServer(13423);
    server.response("binary");
    Runner.running(server, new Runnable() {
        @Override
        public void run() throws Exception {
            final HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
            Request request = new Request();
            request.setBinaryContent(true);
            request.setUrl("http://127.0.0.1:13423/");
            Page page = httpClientDownloader.download(request, Site.me().toTask());
            assertThat(page.getRawText()).isNull();
            assertThat(page.getBytes()).isEqualTo("binary".getBytes());
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:18,代码来源:HttpClientDownloaderTest.java

示例10: test_download_set_request_charset

import com.github.dreamhead.moco.Runnable; //导入依赖的package包/类
@Test
public void test_download_set_request_charset() throws Exception {
    HttpServer server = httpServer(13423);
    server.response("hello world!");
    Runner.running(server, new Runnable() {
        @Override
        public void run() throws Exception {
            final HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
            Request request = new Request();
            request.setCharset("utf-8");
            request.setUrl("http://127.0.0.1:13423/");
            Page page = httpClientDownloader.download(request, Site.me().setCharset("gbk").toTask());
            assertThat(page.getCharset()).isEqualTo("utf-8");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:17,代码来源:HttpClientDownloaderTest.java

示例11: should_complain_bad_request

import com.github.dreamhead.moco.Runnable; //导入依赖的package包/类
@Test
public void should_complain_bad_request() throws Exception {
    running(httpserver(12306), new Runnable() {
        @Override
        public void run() throws Exception {
            try {
                Lurker.loadClass("", "http://localhost:12306/classpath");
                fail();
            } catch (IllegalStateException ignored) { }
        }
    });
}
 
开发者ID:zhongl,项目名称:lurker,代码行数:13,代码来源:LurkerTest.java

示例12: test_set_site_header

import com.github.dreamhead.moco.Runnable; //导入依赖的package包/类
@Test
public void test_set_site_header() throws Exception {
    HttpServer server = httpServer(13423);
    server.get(eq(header("header"), "header-webmagic")).response("ok");
    Runner.running(server, new Runnable() {
        @Override
        public void run() throws Exception {
            HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
            Request request = new Request();
            request.setUrl("http://127.0.0.1:13423");
            Page page = httpClientDownloader.download(request, Site.me().addHeader("header","header-webmagic").toTask());
            assertThat(page.getRawText()).isEqualTo("ok");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:16,代码来源:HttpClientDownloaderTest.java

示例13: test_download_when_task_is_null

import com.github.dreamhead.moco.Runnable; //导入依赖的package包/类
@Test
public void test_download_when_task_is_null() throws Exception {
    HttpServer server = httpServer(13423);
    server.response("foo");
    Runner.running(server, new Runnable() {
        @Override
        public void run() throws Exception {
            final HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
            Request request = new Request();
            request.setUrl("http://127.0.0.1:13423/");
            Page page = httpClientDownloader.download(request, Site.me().toTask());
            assertThat(page.getRawText()).isEqualTo("foo");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:16,代码来源:HttpClientDownloaderTest.java

示例14: test_download_set_charset

import com.github.dreamhead.moco.Runnable; //导入依赖的package包/类
@Test
public void test_download_set_charset() throws Exception {
    HttpServer server = httpServer(13423);
    server.response(header("Content-Type","text/html; charset=utf-8")).response("hello world!");
    Runner.running(server, new Runnable() {
        @Override
        public void run() throws Exception {
            final HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
            Request request = new Request();
            request.setUrl("http://127.0.0.1:13423/");
            Page page = httpClientDownloader.download(request, Site.me().toTask());
            assertThat(page.getCharset()).isEqualTo("utf-8");
        }
    });
}
 
开发者ID:code4craft,项目名称:webmagic,代码行数:16,代码来源:HttpClientDownloaderTest.java


注:本文中的com.github.dreamhead.moco.Runnable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。