Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-demo-single
Overview
Overview
Details
Activity
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
gic_demo
gic-demo-single
Commits
69fe1411
Commit
69fe1411
authored
Jul 17, 2019
by
朱瑞泽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
fc443230
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
206 additions
and
17 deletions
+206
-17
pom.xml
gic-demo-single-service/pom.xml
+1
-1
TestRun.java
...le-service/src/main/java/com/gic/demo/single/TestRun.java
+63
-0
DemoStoreService.java
...in/java/com/gic/demo/single/service/DemoStoreService.java
+3
-0
DemoStoreServiceImpl.java
...om/gic/demo/single/service/impl/DemoStoreServiceImpl.java
+20
-0
DemoStoreApiServiceImpl.java
...mo/single/service/outer/impl/DemoStoreApiServiceImpl.java
+2
-0
jdbc-gic-demo-service.xml
...ngle-service/src/main/resources/jdbc-gic-demo-service.xml
+41
-16
log4j2.xml
gic-demo-single-service/src/main/resources/log4j2.xml
+27
-0
AppTest.java
gic-demo-single-service/src/test/java/com/gic/AppTest.java
+49
-0
No files found.
gic-demo-single-service/pom.xml
View file @
69fe1411
...
...
@@ -117,7 +117,7 @@
<classesDirectory>
target/classes/
</classesDirectory>
<archive>
<manifest>
<mainClass>
com.gic.
commons.DubboMai
n
</mainClass>
<mainClass>
com.gic.
demo.single.TestRu
n
</mainClass>
<!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
<useUniqueVersions>
false
</useUniqueVersions>
<addClasspath>
true
</addClasspath>
...
...
gic-demo-single-service/src/main/java/com/gic/demo/single/TestRun.java
0 → 100644
View file @
69fe1411
package
com
.
gic
.
demo
.
single
;
import
com.gic.demo.single.service.DemoStoreService
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.function.Consumer
;
/**
* @author zhurz
*/
@Component
public
class
TestRun
{
@Value
(
"${jdbc.maxsize}"
)
private
Integer
jdbcMaxsize
;
public
void
test
(
Consumer
<
String
>
consumer
)
throws
InterruptedException
{
int
maxThreadSize
=
100
;
int
size
=
100000
;
ExecutorService
exec
=
Executors
.
newFixedThreadPool
(
maxThreadSize
);
CountDownLatch
countDownLatch
=
new
CountDownLatch
(
size
);
long
begin
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
int
finalI
=
i
;
exec
.
execute
(()
->
{
try
{
consumer
.
accept
(
"sss"
+
finalI
);
}
finally
{
countDownLatch
.
countDown
();
}
});
}
countDownLatch
.
await
();
long
now
=
System
.
currentTimeMillis
();
double
cost
=
((
now
-
begin
)
/
1000
d
);
System
.
out
.
printf
(
"并发线程: %d, jdbc最大连接: %d, 查询次数: %d, 耗时:%.2f s, QPS: %.2f\n"
,
maxThreadSize
,
jdbcMaxsize
,
size
,
cost
,
size
/
cost
);
}
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
ApplicationContext
applicationContext
=
new
ClassPathXmlApplicationContext
(
"applicationContext-conf.xml"
);
TestRun
bean
=
applicationContext
.
getBean
(
TestRun
.
class
);
DemoStoreService
demoStoreService
=
applicationContext
.
getBean
(
DemoStoreService
.
class
);
System
.
out
.
println
(
"无事务"
);
bean
.
test
(
demoStoreService:
:
test1
);
System
.
out
.
println
(
"开启事务"
);
bean
.
test
(
demoStoreService:
:
test2
);
System
.
out
.
println
(
"只读事务"
);
bean
.
test
(
demoStoreService:
:
test3
);
}
}
gic-demo-single-service/src/main/java/com/gic/demo/single/service/DemoStoreService.java
View file @
69fe1411
...
...
@@ -17,4 +17,7 @@ public interface DemoStoreService {
*/
TabGicDemoStore
findDemoStoreById
(
String
storeId
);
void
test1
(
String
storeId
);
void
test2
(
String
storeId
);
void
test3
(
String
storeId
);
}
gic-demo-single-service/src/main/java/com/gic/demo/single/service/impl/DemoStoreServiceImpl.java
View file @
69fe1411
...
...
@@ -6,6 +6,7 @@ import com.gic.demo.single.service.DemoStoreService;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
/**
...
...
@@ -26,10 +27,29 @@ public class DemoStoreServiceImpl implements DemoStoreService {
* @return
*/
@Override
// @Transactional()
// @Transactional(readOnly = true)
public
TabGicDemoStore
findDemoStoreById
(
String
storeId
)
{
if
(
StringUtils
.
isBlank
(
storeId
))
{
return
null
;
}
return
mapper
.
selectByPrimaryKey
(
storeId
);
}
@Override
public
void
test1
(
String
storeId
)
{
mapper
.
selectByPrimaryKey
(
storeId
);
}
@Override
@Transactional
public
void
test2
(
String
storeId
)
{
mapper
.
selectByPrimaryKey
(
storeId
);
}
@Override
@Transactional
(
readOnly
=
true
)
public
void
test3
(
String
storeId
)
{
mapper
.
selectByPrimaryKey
(
storeId
);
}
}
gic-demo-single-service/src/main/java/com/gic/demo/single/service/outer/impl/DemoStoreApiServiceImpl.java
View file @
69fe1411
...
...
@@ -10,6 +10,7 @@ import com.gic.demo.single.service.DemoStoreService;
import
org.apache.commons.lang3.RandomUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
/**
* @author zhurz
...
...
@@ -27,6 +28,7 @@ public class DemoStoreApiServiceImpl implements DemoStoreApiService {
* @return
*/
@Override
@Transactional
public
ServiceResponse
<
DemoStoreDTO
>
findDemoStoreById
(
String
storeId
)
{
if
(
RandomUtils
.
nextInt
(
0
,
10
)
>
5
)
{
return
ServiceResponse
.
failure
(
DemoSinglApiConstant
.
ERROR
,
"服务异常"
);
...
...
gic-demo-single-service/src/main/resources/jdbc-gic-demo-service.xml
View file @
69fe1411
...
...
@@ -4,24 +4,24 @@
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:apollo=
"http://www.ctrip.com/schema/apollo"
xmlns:tx=
"http://www.springframework.org/schema/tx"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.ctrip.com/schema/apollo
http://www.ctrip.com/schema/apollo.xsd"
>
xmlns:aop=
"http://www.springframework.org/schema/aop"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.ctrip.com/schema/apollo http://www.ctrip.com/schema/apollo.xsd
http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd"
>
<context:annotation-config/>
<apollo:config
namespaces=
"COMMON.sharding,COMMON.jdbc"
/
>
<!-- <apollo:config namespaces="COMMON.sharding,COMMON.jdbc"/>--
>
<bean
id=
"dataSource"
class=
"com.gic.sharding.sdk.ShardingDatasource"
init-method=
"init"
>
<property
name=
"shardingId"
value=
"${sharding.shardingId}"
/>
<property
name=
"maxSize"
value=
"${jdbc.maxsize}"
/>
<property
name=
"urlType"
value=
"${sharding.urlType:inner}"
/>
</bean>
<!-- <bean id="dataSource" class="com.gic.sharding.sdk.ShardingDatasource" init-method="init">-->
<!-- <property name="shardingId" value="${sharding.shardingId}"/>-->
<!-- <property name="maxSize" value="${jdbc.maxsize}"/>-->
<!-- <property name="urlType" value="${sharding.urlType:inner}"/>-->
<!-- </bean>-->
<import
resource=
"classpath:applicationContext-db-only.xml"
/>
<bean
class=
"org.mybatis.spring.SqlSessionFactoryBean"
id=
"sqlSessionFactory"
>
<property
name=
"dataSource"
ref=
"dataSource"
/>
...
...
@@ -56,4 +56,30 @@
</bean>
<tx:annotation-driven
transaction-manager=
"txManager"
/>
</beans>
\ No newline at end of file
<!-- <tx:advice id="txAdvice" transaction-manager="txManager">-->
<!-- <tx:attributes>-->
<!-- <!– 设置所有匹配的方法,然后设置传播级别和事务隔离 –>-->
<!-- <!– 增 –>-->
<!-- <tx:method name="insert*" rollback-for="java.lang.Exception"/>-->
<!-- <tx:method name="save*" rollback-for="java.lang.Exception"/>-->
<!-- <tx:method name="add*" rollback-for="java.lang.Exception"/>-->
<!-- <!– 删 –>-->
<!-- <tx:method name="delete*" rollback-for="java.lang.Exception"/>-->
<!-- <tx:method name="remove*" rollback-for="java.lang.Exception"/>-->
<!-- <!– 改 –>-->
<!-- <tx:method name="update*" rollback-for="java.lang.Exception"/>-->
<!-- <!– 查 –>-->
<!-- <tx:method name="get*" read-only="true"/>-->
<!-- <tx:method name="find*" read-only="true"/>-->
<!-- <tx:method name="count*" read-only="true"/>-->
<!-- <tx:method name="list*" read-only="true"/>-->
<!-- <tx:method name="query*" read-only="true"/>-->
<!-- </tx:attributes>-->
<!-- </tx:advice>-->
<!-- <aop:config>-->
<!-- <aop:pointcut id="txPointcut" expression="execution(public * com.gic.demo.single.service..*.*(..))" />-->
<!-- <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" />-->
<!-- </aop:config>-->
</beans>
gic-demo-single-service/src/main/resources/log4j2.xml
0 → 100644
View file @
69fe1411
<?xml version="1.0" encoding="UTF-8"?>
<configuration
status=
"error"
packages=
"com.gic.commons.log"
>
<appenders>
<!--这个输出控制台的配置-->
<Console
name=
"Console"
target=
"SYSTEM_OUT"
>
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
<ThresholdFilter
level=
"trace"
onMatch=
"ACCEPT"
onMismatch=
"DENY"
/>
<!--这个都知道是输出日志的格式-->
<PatternLayout
pattern=
"%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c:%L] [%traceId] %m%n"
/>
</Console>
</appenders>
<loggers>
<!--建立一个默认的root的logger-->
<!-- <Logger name="com.gic" level="DEBUG"/>-->
<Logger
name=
"com.gic"
level=
"WARN"
/>
<!-- <Logger name="org.springframework.jdbc.datasource.DataSourceTransactionManager" level="DEBUG"/>-->
<Logger
name=
"org.springframework.jdbc.datasource.DataSourceTransactionManager"
level=
"WARN"
/>
<logger
name=
"Sharding-JDBC-SQL"
level=
"INFO"
/>
<Root
level=
"WARN"
>
<!-- <Root level="DEBUG">-->
<AppenderRef
ref=
"Console"
/>
</Root>
</loggers>
</configuration>
gic-demo-single-service/src/test/java/com/gic/AppTest.java
View file @
69fe1411
...
...
@@ -6,13 +6,19 @@ import com.gic.demo.single.dao.mapper.DemoEnterpriseMapper;
import
com.gic.demo.single.dao.mapper.DemoStoreMapper
;
import
com.gic.demo.single.entity.TabGicDemoEnterprise
;
import
com.gic.demo.single.entity.TabGicDemoStore
;
import
com.gic.demo.single.service.DemoStoreService
;
import
org.apache.commons.lang3.RandomStringUtils
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
/**
* Unit test for simple App.
*/
...
...
@@ -26,6 +32,9 @@ public class AppTest {
@Autowired
private
DemoStoreMapper
storeMapper
;
@Autowired
private
DemoStoreService
demoStoreService
;
@Test
public
void
test1
()
{
TabGicDemoEnterprise
tabGicDemoEnterprise
=
enterpriseMapper
.
selectByPrimaryKey
(
"22323423"
);
...
...
@@ -52,4 +61,44 @@ public class AppTest {
}
}
@Test
public
void
test4
()
{
TabGicDemoStore
store
=
demoStoreService
.
findDemoStoreById
(
"001d854981019000"
);
System
.
out
.
println
(
JSON
.
toJSONString
(
store
,
true
));
}
@Value
(
"${jdbc.maxsize}"
)
private
Integer
jdbcMaxsize
;
@Test
public
void
test5
()
throws
InterruptedException
{
int
maxThreadSize
=
100
;
int
size
=
50000
;
ExecutorService
exec
=
Executors
.
newFixedThreadPool
(
maxThreadSize
);
CountDownLatch
countDownLatch
=
new
CountDownLatch
(
size
);
long
begin
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
int
finalI
=
i
;
exec
.
execute
(()
->
{
try
{
demoStoreService
.
findDemoStoreById
(
"sss"
+
finalI
);
}
finally
{
countDownLatch
.
countDown
();
}
});
}
countDownLatch
.
await
();
long
now
=
System
.
currentTimeMillis
();
double
cost
=
((
now
-
begin
)
/
1000
d
);
System
.
out
.
printf
(
"并发线程: %d, jdbc最大连接: %d, 查询次数: %d, 耗时:%.2f s, QPS: %.2f"
,
maxThreadSize
,
jdbcMaxsize
,
size
,
cost
,
size
/
cost
);
}
}
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