Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webmagic
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
沈俊林
webmagic
Commits
2768a1ca
Commit
2768a1ca
authored
Mar 01, 2014
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test for cycleTriedTimes and fix cycleTriedTimes inc error #60
parent
bbd0d7e6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
8 deletions
+31
-8
pom.xml
pom.xml
+5
-0
DashBoardController.java
...us/codecraft/webmagic/avalon/web/DashBoardController.java
+1
-1
pom.xml
webmagic-core/pom.xml
+5
-0
HttpClientDownloader.java
...s/codecraft/webmagic/downloader/HttpClientDownloader.java
+1
-1
HttpClientDownloaderTest.java
...decraft/webmagic/downloader/HttpClientDownloaderTest.java
+19
-6
No files found.
pom.xml
View file @
2768a1ca
...
...
@@ -106,6 +106,11 @@
<artifactId>
log4j
</artifactId>
<version>
1.2.17
</version>
</dependency>
<dependency>
<groupId>
org.assertj
</groupId>
<artifactId>
assertj-core
</artifactId>
<version>
1.5.0
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
...
...
webmagic-avalon/src/main/java/us/codecraft/webmagic/avalon/web/DashBoardController.java
View file @
2768a1ca
...
...
@@ -12,7 +12,7 @@ import org.springframework.web.servlet.ModelAndView;
public
class
DashBoardController
{
@RequestMapping
public
ModelAndView
create
()
{
public
ModelAndView
index
()
{
ModelAndView
map
=
new
ModelAndView
(
"dashboard"
);
return
map
;
}
...
...
webmagic-core/pom.xml
View file @
2768a1ca
...
...
@@ -55,6 +55,11 @@
<artifactId>
htmlcleaner
</artifactId>
</dependency>
<dependency>
<groupId>
org.assertj
</groupId>
<artifactId>
assertj-core
</artifactId>
</dependency>
<dependency>
<groupId>
org.jsoup
</groupId>
<artifactId>
jsoup
</artifactId>
...
...
webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpClientDownloader.java
View file @
2768a1ca
...
...
@@ -156,7 +156,7 @@ public class HttpClientDownloader implements Downloader {
if
(
cycleTriedTimes
>=
site
.
getCycleRetryTimes
())
{
return
null
;
}
page
.
addTargetRequest
(
request
.
setPriority
(
0
).
putExtra
(
Request
.
CYCLE_TRIED_TIMES
,
1
));
page
.
addTargetRequest
(
request
.
setPriority
(
0
).
putExtra
(
Request
.
CYCLE_TRIED_TIMES
,
cycleTriedTimes
));
}
return
page
;
}
...
...
webmagic-core/src/test/java/us/codecraft/webmagic/downloader/HttpClientDownloaderTest.java
View file @
2768a1ca
package
us
.
codecraft
.
webmagic
.
downloader
;
import
org.junit.Assert
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
us.codecraft.webmagic.Page
;
import
us.codecraft.webmagic.Request
;
import
us.codecraft.webmagic.Site
;
import
us.codecraft.webmagic.Task
;
import
us.codecraft.webmagic.selector.Html
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
/**
* Author: code4crafer@gmail.com
* Date: 13-6-18
* Time: 上午8:22
* @author code4crafer@gmail.com
*/
public
class
HttpClientDownloaderTest
{
...
...
@@ -21,14 +22,26 @@ public class HttpClientDownloaderTest {
Site
site
=
Site
.
me
().
setDomain
(
"www.diandian.com"
).
addCookie
(
"t"
,
"43ztv9srfszl99yxv2aumx3zr7el7ybb"
);
HttpClientDownloader
httpClientDownloader
=
new
HttpClientDownloader
();
Page
download
=
httpClientDownloader
.
download
(
new
Request
(
"http://www.diandian.com"
),
site
.
toTask
());
Assert
.
assertTrue
(
download
.
getHtml
().
toString
().
contains
(
"flashsword30"
));
assertTrue
(
download
.
getHtml
().
toString
().
contains
(
"flashsword30"
));
}
@Test
public
void
testDownloader
()
{
HttpClientDownloader
httpClientDownloader
=
new
HttpClientDownloader
();
Html
html
=
httpClientDownloader
.
download
(
"http://www.oschina.net"
);
Assert
.
assertTrue
(!
html
.
getText
().
isEmpty
());
assertTrue
(!
html
.
getText
().
isEmpty
());
}
@Test
public
void
testCycleTriedTimes
()
{
HttpClientDownloader
httpClientDownloader
=
new
HttpClientDownloader
();
Task
task
=
Site
.
me
().
setDomain
(
"localhost"
).
setCycleRetryTimes
(
5
).
toTask
();
Request
request
=
new
Request
(
"http://localhost/404"
);
Page
page
=
httpClientDownloader
.
download
(
request
,
task
);
assertThat
(
page
.
getTargetRequests
().
size
()
>
0
);
assertThat
((
Integer
)
page
.
getTargetRequests
().
get
(
0
).
getExtra
(
Request
.
CYCLE_TRIED_TIMES
)).
isEqualTo
(
1
);
page
=
httpClientDownloader
.
download
(
page
.
getTargetRequests
().
get
(
0
),
task
);
assertThat
((
Integer
)
page
.
getTargetRequests
().
get
(
0
).
getExtra
(
Request
.
CYCLE_TRIED_TIMES
)).
isEqualTo
(
2
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment