Toggle navigation
Toggle navigation
This project
Loading...
Sign in
yangyoupeng
/
microservice
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
yangyoupeng
2016-11-28 16:59:30 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
13f38f7d20b291e35086933056eb3f6254ed9688
13f38f7d
1 parent
710c4a50
增加测试,优化,减少网络连接
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
6 deletions
src/microservice-parent/microservice-redis/src/main/java/com/zhaoonline/redis/lock/ExcludeLock.java
src/microservice-parent/microservice-redis/src/test/java/com/zhaoonline/redis/TestExpireOfRedis.java
src/microservice-parent/microservice-redis/src/test/java/com/zhaoonline/redis/lock/TestExcludeLock.java
src/microservice-parent/microservice-redis/src/main/java/com/zhaoonline/redis/lock/ExcludeLock.java
View file @
13f38f7
...
...
@@ -92,7 +92,6 @@ public class ExcludeLock {
logger
.
debug
(
"new lock [{}] setIfAbsent result is [{}]"
,
newLock
,
result
);
if
(
result
)
{
Boolean
expireSetResult
=
valuOper
.
expire
(
lockExpiryInMillis
,
TimeUnit
.
MILLISECONDS
);
this
.
lock
=
newLock
;
return
true
;
}
...
...
src/microservice-parent/microservice-redis/src/test/java/com/zhaoonline/redis/TestExpireOfRedis.java
0 → 100644
View file @
13f38f7
package
com
.
zhaoonline
.
redis
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
org.junit.Test
;
import
org.springframework.data.redis.connection.RedisConnection
;
import
org.springframework.data.redis.connection.jedis.JedisConnectionFactory
;
public
class
TestExpireOfRedis
{
@Test
public
void
testSimpleConnect
()
throws
InterruptedException
{
JedisConnectionFactory
factory
=
new
JedisConnectionFactory
();
factory
.
setHostName
(
"192.168.0.188"
);
factory
.
setPort
(
6377
);
factory
.
setUsePool
(
true
);
factory
.
afterPropertiesSet
();
RedisConnection
connection
=
factory
.
getConnection
();
assertNotNull
(
connection
);
byte
[]
testKey
=
"yyp:test"
.
getBytes
();
connection
.
del
(
testKey
);
boolean
result
=
connection
.
setNX
(
testKey
,
"helloworld"
.
getBytes
());
connection
.
expire
(
testKey
,
30
);
// assertEquals(true, result);
boolean
live
=
true
;
while
(
live
){
Long
ttl
=
connection
.
ttl
(
testKey
);
System
.
out
.
println
(
"ttl left:"
+
ttl
);
if
(
ttl
<
0
){
live
=
false
;
}
Thread
.
sleep
(
500
);
}
//connection.del(testKey);
factory
.
destroy
();
}
}
src/microservice-parent/microservice-redis/src/test/java/com/zhaoonline/redis/lock/TestExcludeLock.java
View file @
13f38f7
...
...
@@ -41,13 +41,13 @@ public class TestExcludeLock {
@Test
public
void
testfailedAquireLockAfterHasBeenLock
()
throws
InterruptedException
{
ExcludeLock
lock
=
new
ExcludeLock
(
factory
,
testLock
);
ExcludeLock
lock
=
new
ExcludeLock
(
factory
,
testLock
,
3000
,
30000
);
Boolean
lockAcquirereuslt
=
lock
.
acquireLock
();
assertTrue
(
lockAcquirereuslt
);
Thread
.
sleep
(
3000
);
ExcludeLock
lock2
=
new
ExcludeLock
(
factory
,
testLock
);
Boolean
lockAcquirereuslt2
=
lock2
.
acquireLock
();
assertTrue
(
lockAcquirereuslt2
);
//
Thread.sleep(3000);
//
ExcludeLock lock2 = new ExcludeLock(factory, testLock);
//
Boolean lockAcquirereuslt2 = lock2.acquireLock();
//
assertTrue(lockAcquirereuslt2);
lock
.
getRedisTemplate
().
delete
(
lock
.
getLockKeyPath
());
}
...
...
@@ -72,6 +72,7 @@ public class TestExcludeLock {
factory
.
setHostName
(
"192.168.0.188"
);
factory
.
setPort
(
6377
);
factory
.
setUsePool
(
true
);
factory
.
setDatabase
(
0
);
factory
.
afterPropertiesSet
();
return
factory
;
}
...
...
Please
register
or
login
to post a comment