Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oto
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
龚小红
oto
Commits
c615f189
Commit
c615f189
authored
Oct 14, 2021
by
xiamengchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
秒杀限制需求合入
parent
ca2bb3bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
6 deletions
+100
-6
SecondKill.java
src/test/java/com/kjj/cases/live/secondKill/SecondKill.java
+98
-6
BasicConfig.java
src/test/java/com/kjj/config/BasicConfig.java
+2
-0
No files found.
src/test/java/com/kjj/cases/live/secondKill/SecondKill.java
View file @
c615f189
...
...
@@ -14,14 +14,12 @@ import org.testng.Assert;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.Test
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
import
static
com
.
kjj
.
utils
.
ThreadSleepUtils
.
sleep
;
public
class
SecondKill
implements
Authorization
{
private
List
<
Long
>
confIds
;
@BeforeClass
public
void
setUp
(){
...
...
@@ -638,7 +636,101 @@ public class SecondKill implements Authorization {
}
}
@Test
(
description
=
"删除已上架过的轮次"
,
priority
=
30
)
// 秒杀限制
@Test
(
description
=
"添加秒杀限制"
,
priority
=
30
)
public
void
添加秒杀限制
()
{
confIds
=
new
ArrayList
<>();
// 用户已成功下单0元秒杀商品
// 将0元秒杀商品和第二轮秒杀添加进限制组
confIds
.
add
(
IdMakeUtil
.
managerDecodeingId
(
ConfSecondKill
.
skIdThird
));
confIds
.
add
(
IdMakeUtil
.
managerDecodeingId
(
ConfSecondKill
.
skIdSecond
));
Map
<
String
,
Object
>
addLimitPar
=
new
HashMap
<>();
addLimitPar
.
put
(
"confIds"
,
confIds
);
addLimitPar
.
put
(
"liveId"
,
LiveConstants
.
getValue
(
LiveConstants
.
StringKeyEnum
.
LIVE_ID
.
getKey
()));
Response
addLimitRes
=
network
.
postResponse
(
addLimitPar
,
BasicConfig
.
MANAGER_secondKillSaveLimitGroup
);
try
{
boolean
data
=
addLimitRes
.
jsonPath
().
getBoolean
(
"data"
);
Assert
.
assertTrue
(
data
,
network
.
message
(
addLimitPar
,
BasicConfig
.
MANAGER_secondKillSaveLimitGroup
,
"添加秒杀限制失败"
,
addLimitRes
.
body
().
asString
()));
}
catch
(
NullPointerException
e
){
e
.
printStackTrace
();
Assert
.
fail
(
network
.
message
(
addLimitPar
,
BasicConfig
.
MANAGER_secondKillSaveLimitGroup
,
"获取数据失败"
,
addLimitRes
.
body
().
asString
()));
}
}
@Test
(
description
=
"查询秒杀限制组"
,
priority
=
31
)
public
void
查询秒杀限制组
()
{
Map
<
String
,
Object
>
limitGroupListPar
=
new
HashMap
<>();
limitGroupListPar
.
put
(
"liveId"
,
LiveConstants
.
getValue
(
LiveConstants
.
StringKeyEnum
.
LIVE_ID
.
getKey
()));
Response
limitGroupListRes
=
network
.
getResponse
(
limitGroupListPar
,
BasicConfig
.
MANAGER_secondKillLimitGroupList
);
try
{
List
<
Object
>
data
=
limitGroupListRes
.
jsonPath
().
getList
(
"data"
);
if
(
data
.
size
()
!=
confIds
.
size
()){
Assert
.
fail
(
network
.
message
(
limitGroupListPar
,
BasicConfig
.
MANAGER_secondKillLimitGroupList
,
"秒杀限制组与预定配置不一致"
,
limitGroupListRes
.
body
().
asString
()));
}
for
(
int
i
=
0
;
i
<
data
.
size
();
i
++){
Assert
.
assertEquals
(
data
.
get
(
i
).
toString
(),
confIds
.
get
(
i
).
toString
(),
network
.
message
(
limitGroupListPar
,
BasicConfig
.
MANAGER_secondKillLimitGroupList
,
"秒杀限制组与预定配置不一致"
,
limitGroupListRes
.
body
().
asString
()));
}
}
catch
(
NullPointerException
e
){
e
.
printStackTrace
();
Assert
.
fail
(
network
.
message
(
limitGroupListPar
,
BasicConfig
.
MANAGER_secondKillLimitGroupList
,
"获取数据失败"
,
limitGroupListRes
.
body
().
asString
()));
}
}
@Test
(
description
=
"限制组限制用户下单"
,
priority
=
32
)
public
void
限制组限制用户下单
()
{
// 等待两分钟代理人释放第二轮次库存
ThreadSleepUtils
.
sleep
(
180000
);
// 用户下单
visitorAuth
();
Map
<
String
,
Object
>
orderPar
=
new
HashMap
<>();
orderPar
.
put
(
"liveId"
,
LiveConstants
.
getValue
(
LiveConstants
.
StringKeyEnum
.
ENCODE_LIVE_ID
.
getKey
()));
orderPar
.
put
(
"confId"
,
ConfSecondKill
.
skIdSecond
);
Response
orderRes
=
network
.
postResponse
(
orderPar
,
BasicConfig
.
MOBILE_secondKill_goodsOrder
);
try
{
boolean
data
=
orderRes
.
jsonPath
().
getBoolean
(
"data"
);
Assert
.
assertTrue
(
data
,
network
.
message
(
orderPar
,
BasicConfig
.
MOBILE_secondKill_goodsOrder
,
"下单失败"
,
orderRes
.
body
().
asString
()));
}
catch
(
NullPointerException
e
){
e
.
printStackTrace
();
Assert
.
fail
(
network
.
message
(
orderPar
,
BasicConfig
.
MOBILE_secondKill_goodsOrder
,
"未获取到数据"
,
orderRes
.
body
().
asString
()));
}
Map
<
String
,
Object
>
orderResultPar
=
new
HashMap
<>();
orderResultPar
.
put
(
"liveId"
,
LiveConstants
.
getValue
(
LiveConstants
.
StringKeyEnum
.
ENCODE_LIVE_ID
.
getKey
()));
orderResultPar
.
put
(
"confId"
,
ConfSecondKill
.
skIdSecond
);
Response
orderResultRes
=
null
;
Object
data
=
null
;
int
i
=
0
;
try
{
// 轮训下单接口
while
(
data
==
null
){
sleep
(
2000
);
orderResultRes
=
network
.
getResponse
(
orderResultPar
,
BasicConfig
.
MOBILE_secondKill_goodsOrderResult
);
data
=
orderResultRes
.
jsonPath
().
getJsonObject
(
"data"
);
System
.
out
.
println
(
"data: "
+
data
);
i
++;
if
(
i
==
10
){
Assert
.
fail
(
network
.
message
(
orderResultPar
,
BasicConfig
.
MOBILE_secondKill_goodsOrderResult
,
"轮训下单结果超过10次"
,
orderResultRes
.
body
().
asString
()));
}
}
int
state
=
orderResultRes
.
jsonPath
().
getInt
(
"data.state"
);
if
(
state
==
2
){
int
code
=
orderResultRes
.
jsonPath
().
getInt
(
"data.code"
);
if
(
code
==
4
){
System
.
out
.
println
(
"失败原因code="
+
code
);
}
else
{
Assert
.
assertEquals
(
code
,
3
,
network
.
message
(
orderResultPar
,
BasicConfig
.
MOBILE_secondKill_goodsOrderResult
,
"失败原因不是被限制"
,
orderResultRes
.
body
().
asString
()));
}
}
else
{
Assert
.
fail
(
network
.
message
(
orderResultPar
,
BasicConfig
.
MOBILE_secondKill_goodsOrderResult
,
"用户下单未收到限制组限制"
,
orderResultRes
.
body
().
asString
()));
}
}
catch
(
Exception
e
){
e
.
printStackTrace
();
Assert
.
fail
(
network
.
message
(
orderResultPar
,
BasicConfig
.
MOBILE_secondKill_goodsOrderResult
,
"获取数据失败"
,
orderResultRes
.
body
().
asString
()));
}
}
@Test
(
description
=
"删除已上架过的轮次"
,
priority
=
33
)
public
void
已上架过的轮次无法删除
()
{
long
id
=
IdMakeUtil
.
managerDecodeingId
(
ConfSecondKill
.
skIdFirst
);
Map
<
String
,
Object
>
delSkPar
=
new
HashMap
<>();
...
...
@@ -657,7 +749,7 @@ public class SecondKill implements Authorization {
}
}
@Test
(
description
=
"用户成功支付"
,
priority
=
3
1
)
@Test
(
description
=
"用户成功支付"
,
priority
=
3
4
)
public
void
用户成功支付
()
{
visitorAuth
();
// 新建订单
...
...
src/test/java/com/kjj/config/BasicConfig.java
View file @
c615f189
...
...
@@ -138,6 +138,8 @@ public class BasicConfig {
public
static
final
String
MANAGER_secondKillLists
=
MANAGER_HOST
+
"/kjy/manager/live/second/kill/goods/list"
;
public
static
final
String
MANAGER_secondKillDel
=
MANAGER_HOST
+
"/kjy/manager/live/second/kill/goods/delete"
;
public
static
final
String
MANAGER_secondKillUpdate
=
MANAGER_HOST
+
"/kjy/manager/live/second/kill/goods/update"
;
public
static
final
String
MANAGER_secondKillSaveLimitGroup
=
MANAGER_HOST
+
"/kjy/manager/live/second/kill/goods/saveLimitGroup"
;
public
static
final
String
MANAGER_secondKillLimitGroupList
=
MANAGER_HOST
+
"/kjy/manager/live/second/kill/goods/limitGroupList"
;
public
static
final
String
ANCHOR_secondKillSave
=
MOBILE_HOST
+
"/conf/live/second/kill/goods/save"
;
public
static
final
String
ANCHOR_secondKillLists
=
MOBILE_HOST
+
"/conf/live/second/kill/goods/list"
;
public
static
final
String
ANCHOR_secondKillUpdate
=
MOBILE_HOST
+
"/conf/live/second/kill/goods/update"
;
...
...
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