當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。