Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
test-platform
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
马博
test-platform
Commits
1450fa8e
Commit
1450fa8e
authored
Oct 30, 2019
by
马博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
84115892
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
389 additions
and
0 deletions
+389
-0
集卡_ConcurrentTest.java
...est/java/http/cases/ConcurrentTest/集卡_ConcurrentTest.java
+93
-0
夺宝签到_signTest.java
src/test/java/http/cases/SignTest/夺宝签到_signTest.java
+85
-0
夺宝签到开奖_signTest.java
src/test/java/http/cases/SignTest/夺宝签到开奖_signTest.java
+65
-0
SignTreasureService.java
src/test/java/http/service/Activity/SignTreasureService.java
+146
-0
No files found.
src/test/java/http/cases/ConcurrentTest/集卡_ConcurrentTest.java
0 → 100644
View file @
1450fa8e
package
http
.
cases
.
ConcurrentTest
;
import
base.DuibaTestBase
;
import
http.service.Authorization
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.Test
;
import
java.sql.SQLException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
static
io
.
restassured
.
RestAssured
.
given
;
/**
* Created by mabo on 2019/8/28
*/
public
class
集卡
_ConcurrentTest
extends
DuibaTestBase
{
private
String
url
=
"http://activity.m.duibatest.com.cn"
;
@Autowired
Authorization
authorization
;
private
int
uid
=
2691
;
private
String
collectRuleId
=
"5193"
;
private
List
<
String
>
responselist
=
new
ArrayList
();
@BeforeClass
public
void
beforeclass
(){
try
{
jdbc
.
update
(
"UPDATE collect_card_consumer.tb_collect_card_info_0614 set item_count=1 where item_id=32675"
);
jdbc
.
update
(
"UPDATE collect_card_consumer.tb_collect_card_info_0614 set item_count=1 where item_id=32674"
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
}
@Test
(
threadPoolSize
=
5
,
invocationCount
=
5
)
public
void
卡片库存不足并发
()
throws
InterruptedException
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"collectRuleId"
,
collectRuleId
);
Response
response
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
uid
)).
params
(
map
).
get
(
url
+
"/plugin/collectRule/openCollectGoodsPrize"
);
String
result
=
response
.
asString
();
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
//设置日期格式
System
.
out
.
println
(
df
.
format
(
new
Date
()));
synchronized
(
this
){
Thread
.
sleep
(
5000
);
responselist
.
add
(
result
);
}
System
.
out
.
println
(
df
.
format
(
new
Date
()));
}
@Test
(
dependsOnMethods
=
"卡片库存不足并发"
)
public
void
校验
()
throws
SQLException
{
int
i
=
0
;
int
j
=
0
;
for
(
String
s:
responselist
)
{
if
(
s
.
contains
(
"重复下单"
))
i
++;
if
(
s
.
contains
(
"orderId"
))
j
++;
}
Assert
.
assertEquals
(
i
,
4
);
Assert
.
assertEquals
(
j
,
1
);
logger
.
info
(
"校验并发结果集正确"
);
Map
map
=
jdbc
.
findSimpleResult
(
"select * from collect_card_consumer.tb_collect_card_info_0614 where item_id=32674"
);
int
count
=
(
int
)
map
.
get
(
"item_count"
);
Assert
.
assertEquals
(
count
,
0
);
map
=
jdbc
.
findSimpleResult
(
"select * from collect_card_consumer.tb_collect_card_info_0614 where item_id=32675"
);
count
=
(
int
)
map
.
get
(
"item_count"
);
Assert
.
assertEquals
(
count
,
0
);
logger
.
info
(
"校验卡片库存正确"
);
}
@Test
public
void
test
(){
}
}
src/test/java/http/cases/SignTest/夺宝签到_signTest.java
0 → 100644
View file @
1450fa8e
package
http
.
cases
.
SignTest
;
import
base.DuibaTestBase
;
import
http.service.Activity.SignTreasureService
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.Assert
;
import
org.testng.annotations.AfterMethod
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.Test
;
import
java.sql.SQLException
;
import
java.util.Map
;
/**
* Created by mabo on 2019/10/23
*/
public
class
夺宝签到
_signTest
extends
DuibaTestBase
{
@Autowired
SignTreasureService
signTreasureService
;
private
String
phaseId
=
"1"
;
private
String
id
=
"187"
;
private
int
uid
=
7003
;
//7003 6926
@BeforeMethod
public
void
before
(){
try
{
jdbc
.
update
(
"delete from sign_record.tb_sign_treasure_user_record where consumer_id=100144145"
);
jdbc
.
update
(
"delete from sign_record.tb_sign_treasure_code_detail where consumer_id=100144145"
);
jdbc
.
update
(
"delete from sign_record.tb_sign_log where consumer_id=100144145"
);
jdbc
.
update
(
"delete from sign_record.tb_sign_statics where consumer_id=100144145"
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
签到
()
throws
Exception
{
//获取签到信息
Response
response
=
signTreasureService
.
getHomeInfo
(
id
,
uid
);
//校验今日未签到
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"data.todaySigned"
).
equals
(
"false"
));
//签到
response
=
signTreasureService
.
doSign
(
phaseId
,
id
,
uid
);
//获取logId
String
logId
=
response
.
jsonPath
().
getString
(
"data.logId"
);
//获取签到结果
Thread
.
sleep
(
3000
);
response
=
signTreasureService
.
getSignResult
(
logId
,
uid
);
//校验夺宝码
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"data.codes"
).
equals
(
"[102_114_14_84]"
));
//校验已签到
response
=
signTreasureService
.
getHomeInfo
(
id
,
uid
);
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"data.todaySigned"
).
equals
(
"true"
));
}
@Test
public
void
兑换夺宝码
()
throws
Exception
{
Map
<
String
,
Object
>
mapuser
=
jdbc
.
findSimpleResult
(
"select * from dafuweng.user where id="
+
uid
);
String
dafuwengCredits
=
String
.
valueOf
(
mapuser
.
get
(
"credits"
));
//兑换的个数
String
codeCount
=
"1"
;
Response
response
=
signTreasureService
.
exchange
(
phaseId
,
"1"
,
id
,
uid
);
String
orderNum
=
response
.
jsonPath
().
getString
(
"data"
);
Thread
.
sleep
(
5000
);
response
=
signTreasureService
.
orderStatus
(
phaseId
,
orderNum
,
uid
);
response
.
prettyPrint
();
System
.
out
.
println
(
response
.
jsonPath
().
getString
(
"data.codes"
));
//校验夺宝码
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"data.codes"
).
equals
(
"[102_114_14_84]"
));
mapuser
=
jdbc
.
findSimpleResult
(
"select * from dafuweng.user where id="
+
uid
);
String
dafuwengCreditsNew
=
String
.
valueOf
(
mapuser
.
get
(
"credits"
));
Assert
.
assertTrue
(
String
.
valueOf
(
Integer
.
valueOf
(
dafuwengCredits
)-
1
).
equals
(
dafuwengCreditsNew
));
}
}
src/test/java/http/cases/SignTest/夺宝签到开奖_signTest.java
0 → 100644
View file @
1450fa8e
package
http
.
cases
.
SignTest
;
import
base.DuibaBase
;
import
base.DuibaTestBase
;
import
http.service.Activity.SignTreasureService
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.Test
;
import
java.sql.SQLException
;
import
java.util.List
;
import
java.util.concurrent.CopyOnWriteArrayList
;
/**
* Created by mabo on 2019/10/24
*/
public
class
夺宝签到开奖
_signTest
extends
DuibaTestBase
{
@Autowired
SignTreasureService
signTreasureService
;
private
String
phaseId
=
"1"
;
private
String
id
=
"188"
;
private
int
uid
=
6926
;
private
List
<
String
>
resultList
=
new
CopyOnWriteArrayList
<>();
@BeforeClass
public
void
before
(){
try
{
jdbc
.
update
(
"delete from sign_record.tb_sign_win_record where consumer_id=100144031"
);
jdbc
.
update
(
"update sign_record.tb_sign_treasure_code_detail set reward_status=1 where consumer_id=100144031"
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
//同一用户并发开奖
@Test
(
threadPoolSize
=
5
,
invocationCount
=
5
)
public
void
开奖
()
throws
Exception
{
Response
response
=
signTreasureService
.
getReward
(
"41"
,
id
,
uid
);
resultList
.
add
(
response
.
asString
());
}
@Test
(
dependsOnMethods
=
"开奖"
)
public
void
checkResult
(){
int
fail
=
0
;
int
success
=
0
;
for
(
String
s:
resultList
)
{
if
(
s
.
contains
(
"操作太过频繁,请稍后再试"
)){
fail
++;
}
else
if
(
s
.
contains
(
"\"prizeDetailUrl\":\"/activity/takePrizeNew?recordId="
)){
success
++;
}
else
{
System
.
out
.
println
(
s
);
}
}
//检验 成功的只有一个
Assert
.
assertEquals
(
fail
,
4
);
Assert
.
assertEquals
(
success
,
1
);
}
}
src/test/java/http/service/Activity/SignTreasureService.java
0 → 100644
View file @
1450fa8e
package
http
.
service
.
Activity
;
import
base.DuibaLog
;
import
base.DuibaTestBase
;
import
http.service.Authorization
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.testng.Assert
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
io
.
restassured
.
RestAssured
.
given
;
/**
* Created by mabo on 2019/10/23
* 夺宝签到
*/
@Service
public
class
SignTreasureService
{
@Value
(
"${activity.host}"
)
String
activityHost
;
@Value
(
"${hdserver.host}"
)
String
hdHost
;
@Autowired
Authorization
authorization
;
private
DuibaLog
logger
=
DuibaLog
.
getLogger
();
public
Response
doSign
(
String
phaseId
,
String
id
,
int
uid
)
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"phaseId"
,
phaseId
);
map
.
put
(
"id"
,
id
);
logger
.
info
(
"请求sign接口,签到活动id="
+
id
);
Response
response
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
uid
)).
params
(
map
).
post
(
activityHost
+
"/sign/treasure/sign"
);
try
{
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"/sign/treasure/sign接口失败"
);
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"/sign/treasure/sign接口失败,返回信息:"
+
response
.
asString
());
}
catch
(
Error
er
)
{
throw
new
Exception
(
"/sign/treasure/sign接口失败,返回信息:"
+
response
.
asString
());
}
return
response
;
}
public
Response
getHomeInfo
(
String
id
,
int
uid
)
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"id"
,
id
);
logger
.
info
(
"请求HomeInfo接口,签到活动id="
+
id
);
Response
response
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
uid
)).
params
(
map
).
get
(
activityHost
+
"/sign/treasure/homeInfo"
);
try
{
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"/sign/treasure/homeInfo接口请求失败"
);
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"/sign/treasure/homeInfo接口失败,返回信息"
+
response
.
asString
());
}
catch
(
Error
er
)
{
throw
new
Exception
(
"/sign/treasure/homeInfo接口失败,返回信息:"
+
response
.
asString
());
}
return
response
;
}
public
Response
getSignResult
(
String
logId
,
int
uid
)
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"logId"
,
logId
);
logger
.
info
(
"请求getSignResult接口,logId="
+
logId
);
Response
response
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
uid
)).
params
(
map
).
get
(
activityHost
+
"/sign/treasure/getSignResult"
);
try
{
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"/sign/treasure/getSignResult接口请求失败"
);
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"/sign/treasure/getSignResult接口失败,返回信息"
+
response
.
asString
());
}
catch
(
Error
er
)
{
throw
new
Exception
(
"/sign/treasure/getSignResult接口失败,返回信息:"
+
response
.
asString
());
}
return
response
;
}
public
Response
exchange
(
String
phaseId
,
String
codeCount
,
String
id
,
int
uid
)
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"phaseId"
,
phaseId
);
map
.
put
(
"codeCount"
,
codeCount
);
map
.
put
(
"id"
,
id
);
logger
.
info
(
"请求exchange接口,签到活动id="
+
id
);
Response
response
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
uid
)).
params
(
map
).
post
(
activityHost
+
"/sign/treasure/exchange"
);
try
{
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"/sign/treasure/exchange接口请求失败"
);
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"/sign/treasure/exchange接口失败,返回信息"
+
response
.
asString
());
}
catch
(
Error
er
)
{
throw
new
Exception
(
"/sign/treasure/exchange接口失败,返回信息:"
+
response
.
asString
());
}
return
response
;
}
public
Response
orderStatus
(
String
phaseId
,
String
orderNum
,
int
uid
)
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"phaseId"
,
phaseId
);
map
.
put
(
"orderNum"
,
orderNum
);
logger
.
info
(
"请求orderStatus接口,签到活动orderNum="
+
orderNum
);
Response
response
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
uid
)).
params
(
map
).
get
(
activityHost
+
"/sign/treasure/orderStatus"
);
try
{
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"/sign/treasure/orderStatus接口请求失败"
);
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"/sign/treasure/orderStatus接口失败,返回信息"
+
response
.
asString
());
}
catch
(
Error
er
)
{
throw
new
Exception
(
"/sign/treasure/orderStatus接口失败,返回信息:"
+
response
.
asString
());
}
return
response
;
}
public
Response
getReward
(
String
detailId
,
String
id
,
int
uid
)
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"detailId"
,
detailId
);
map
.
put
(
"id"
,
id
);
logger
.
info
(
"请求getReward接口,id="
+
detailId
);
Response
response
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
uid
)).
params
(
map
).
post
(
activityHost
+
"/sign/treasure/getReward"
);
// try{
// Assert.assertEquals(response.jsonPath().getString("success"), "true", "/sign/treasure/getReward接口请求失败");
// } catch (Exception e) {
// throw new Exception("/sign/treasure/getReward接口失败,返回信息" + response.asString());
// } catch (Error er) {
// throw new Exception("/sign/treasure/getReward接口失败,返回信息:" + response.asString());
// }
return
response
;
}
public
Response
waitWinRecord
(
String
id
,
int
uid
)
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"id"
,
id
);
logger
.
info
(
"请求waitWinRecord接口,id="
+
id
);
Response
response
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
uid
)).
params
(
map
).
get
(
activityHost
+
"/sign/treasure/waitWinRecord"
);
try
{
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"/sign/treasure/waitWinRecord接口请求失败"
);
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"/sign/treasure/waitWinRecord接口失败,返回信息"
+
response
.
asString
());
}
catch
(
Error
er
)
{
throw
new
Exception
(
"/sign/treasure/waitWinRecord接口失败,返回信息:"
+
response
.
asString
());
}
return
response
;
}
}
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