Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
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
openSource
apollo
Commits
dc9df2da
Commit
dc9df2da
authored
Apr 15, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Transactional support and test case
parent
8ea9fa8e
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
142 additions
and
8 deletions
+142
-8
App.java
...lo-biz/src/main/java/com/ctrip/apollo/biz/entity/App.java
+1
-1
AdminService.java
.../main/java/com/ctrip/apollo/biz/service/AdminService.java
+3
-0
AppService.java
...rc/main/java/com/ctrip/apollo/biz/service/AppService.java
+4
-0
ClusterService.java
...ain/java/com/ctrip/apollo/biz/service/ClusterService.java
+4
-0
ItemService.java
...c/main/java/com/ctrip/apollo/biz/service/ItemService.java
+4
-0
ItemSetService.java
...ain/java/com/ctrip/apollo/biz/service/ItemSetService.java
+2
-0
NamespaceService.java
...n/java/com/ctrip/apollo/biz/service/NamespaceService.java
+4
-0
PrivilegeService.java
...n/java/com/ctrip/apollo/biz/service/PrivilegeService.java
+3
-0
ReleaseService.java
...ain/java/com/ctrip/apollo/biz/service/ReleaseService.java
+2
-0
AllTests.java
apollo-biz/src/test/java/com/ctrip/apollo/biz/AllTests.java
+3
-1
AppRepositoryTest.java
...va/com/ctrip/apollo/biz/repository/AppRepositoryTest.java
+5
-6
AdminServiceTest.java
...t/java/com/ctrip/apollo/biz/service/AdminServiceTest.java
+5
-0
AdminServiceTransactionTest.java
...ctrip/apollo/biz/service/AdminServiceTransactionTest.java
+97
-0
PrivilegeServiceTest.java
...va/com/ctrip/apollo/biz/service/PrivilegeServiceTest.java
+5
-0
No files found.
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/App.java
View file @
dc9df2da
...
...
@@ -22,7 +22,7 @@ public class App extends BaseEntity {
@Column
(
name
=
"OwnerName"
,
nullable
=
false
)
private
String
ownerName
;
@Column
(
name
=
"O
nw
erEmail"
,
nullable
=
false
)
@Column
(
name
=
"O
wn
erEmail"
,
nullable
=
false
)
private
String
ownerEmail
;
public
String
getAppId
()
{
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AdminService.java
View file @
dc9df2da
...
...
@@ -2,6 +2,7 @@ package com.ctrip.apollo.biz.service;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ctrip.apollo.biz.entity.App
;
import
com.ctrip.apollo.biz.entity.AppNamespace
;
...
...
@@ -15,6 +16,7 @@ import com.ctrip.apollo.core.ConfigConsts;
import
java.util.Date
;
@Service
public
class
AdminService
{
...
...
@@ -30,6 +32,7 @@ public class AdminService {
@Autowired
private
ClusterRepository
clusterRepository
;
@Transactional
public
App
createNewApp
(
App
app
)
{
String
createBy
=
app
.
getDataChangeCreatedBy
();
App
createdApp
=
appRepository
.
save
(
app
);
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AppService.java
View file @
dc9df2da
...
...
@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ctrip.apollo.biz.entity.App
;
import
com.ctrip.apollo.biz.repository.AppRepository
;
...
...
@@ -17,6 +18,7 @@ public class AppService {
@Autowired
private
AppRepository
appRepository
;
@Transactional
public
void
delete
(
long
id
)
{
appRepository
.
delete
(
id
);
}
...
...
@@ -34,10 +36,12 @@ public class AppService {
return
appRepository
.
findByAppId
(
appId
);
}
@Transactional
public
App
save
(
App
entity
)
{
return
appRepository
.
save
(
entity
);
}
@Transactional
public
App
update
(
App
app
)
{
App
managedApp
=
appRepository
.
findByAppId
(
app
.
getAppId
());
BeanUtils
.
copyEntityProperties
(
app
,
managedApp
);
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ClusterService.java
View file @
dc9df2da
...
...
@@ -2,6 +2,7 @@ package com.ctrip.apollo.biz.service;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.repository.ClusterRepository
;
...
...
@@ -17,14 +18,17 @@ public class ClusterService {
return
clusterRepository
.
findByAppIdAndName
(
appId
,
name
);
}
@Transactional
public
Cluster
save
(
Cluster
entity
)
{
return
clusterRepository
.
save
(
entity
);
}
@Transactional
public
void
delete
(
long
id
)
{
clusterRepository
.
delete
(
id
);
}
@Transactional
public
Cluster
update
(
Cluster
cluster
)
{
Cluster
managedCluster
=
clusterRepository
.
findByAppIdAndName
(
cluster
.
getAppId
(),
cluster
.
getName
());
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ItemService.java
View file @
dc9df2da
...
...
@@ -2,6 +2,7 @@ package com.ctrip.apollo.biz.service;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
...
...
@@ -13,6 +14,7 @@ public class ItemService {
@Autowired
private
ItemRepository
itemRepository
;
@Transactional
public
void
delete
(
long
id
)
{
itemRepository
.
delete
(
id
);
}
...
...
@@ -22,10 +24,12 @@ public class ItemService {
return
item
;
}
@Transactional
public
Item
save
(
Item
item
)
{
return
itemRepository
.
save
(
item
);
}
@Transactional
public
Item
update
(
Item
item
)
{
Item
managedItem
=
itemRepository
.
findOne
(
item
.
getId
());
BeanUtils
.
copyEntityProperties
(
item
,
managedItem
);
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ItemSetService.java
View file @
dc9df2da
...
...
@@ -2,6 +2,7 @@ package com.ctrip.apollo.biz.service;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
...
...
@@ -15,6 +16,7 @@ public class ItemSetService {
@Autowired
private
ItemRepository
itemRepository
;
@Transactional
public
void
updateSet
(
ItemChangeSets
changeSet
)
{
if
(
changeSet
.
getCreateItems
()
!=
null
)
{
for
(
ItemDTO
item
:
changeSet
.
getCreateItems
())
{
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/NamespaceService.java
View file @
dc9df2da
...
...
@@ -2,6 +2,7 @@ package com.ctrip.apollo.biz.service;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ctrip.apollo.biz.entity.Namespace
;
import
com.ctrip.apollo.biz.repository.NamespaceRepository
;
...
...
@@ -13,6 +14,7 @@ public class NamespaceService {
@Autowired
private
NamespaceRepository
namespaceRepository
;
@Transactional
public
void
delete
(
long
id
)
{
namespaceRepository
.
delete
(
id
);
}
...
...
@@ -26,10 +28,12 @@ public class NamespaceService {
namespaceName
);
}
@Transactional
public
Namespace
save
(
Namespace
entity
)
{
return
namespaceRepository
.
save
(
entity
);
}
@Transactional
public
Namespace
update
(
Namespace
namespace
)
{
Namespace
managedNamespace
=
namespaceRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
namespace
.
getAppId
(),
namespace
.
getClusterName
(),
namespace
.
getNamespaceName
());
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/PrivilegeService.java
View file @
dc9df2da
...
...
@@ -5,6 +5,7 @@ import com.ctrip.apollo.biz.repository.PrivilegeRepository;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
...
...
@@ -18,6 +19,7 @@ public class PrivilegeService {
@Autowired
private
PrivilegeRepository
privilRepo
;
@Transactional
public
Privilege
addPrivilege
(
long
namespaceId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByNamespaceIdAndNameAndPrivilType
(
namespaceId
,
name
,
privilType
.
name
());
...
...
@@ -41,6 +43,7 @@ public class PrivilegeService {
return
privilRepo
.
findByNamespaceId
(
namespaceId
);
}
@Transactional
public
void
removePrivilege
(
long
namespaceId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByNamespaceIdAndNameAndPrivilType
(
namespaceId
,
name
,
privilType
.
name
());
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ReleaseService.java
View file @
dc9df2da
...
...
@@ -7,6 +7,7 @@ import java.util.Map;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.entity.Namespace
;
...
...
@@ -40,6 +41,7 @@ public class ReleaseService {
return
release
;
}
@Transactional
public
Release
buildRelease
(
String
name
,
String
comment
,
String
appId
,
String
clusterName
,
String
namespaceName
)
{
Namespace
namespace
=
namespaceRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
...
...
apollo-biz/src/test/java/com/ctrip/apollo/biz/AllTests.java
View file @
dc9df2da
...
...
@@ -2,6 +2,7 @@ package com.ctrip.apollo.biz;
import
com.ctrip.apollo.biz.repository.AppRepositoryTest
;
import
com.ctrip.apollo.biz.service.AdminServiceTest
;
import
com.ctrip.apollo.biz.service.AdminServiceTransactionTest
;
import
com.ctrip.apollo.biz.service.ConfigServiceTest
;
import
com.ctrip.apollo.biz.service.PrivilegeServiceTest
;
...
...
@@ -14,7 +15,8 @@ import org.junit.runners.Suite.SuiteClasses;
AppRepositoryTest
.
class
,
AdminServiceTest
.
class
,
ConfigServiceTest
.
class
,
PrivilegeServiceTest
.
class
})
PrivilegeServiceTest
.
class
,
AdminServiceTransactionTest
.
class
})
public
class
AllTests
{
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/repository/AppRepositoryTest.java
View file @
dc9df2da
package
com
.
ctrip
.
apollo
.
biz
.
repository
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ctrip.apollo.biz.BizTestConfiguration
;
import
com.ctrip.apollo.biz.entity.App
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
BizTestConfiguration
.
class
)
@Transactional
@Rollback
public
class
AppRepositoryTest
{
@Autowired
private
AppRepository
appRepository
;
@Before
public
void
before
()
{
appRepository
.
deleteAll
();
}
@Test
public
void
testCreate
()
{
String
appId
=
"someAppId"
;
...
...
@@ -66,4 +64,5 @@ public class AppRepositoryTest {
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
}
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/AdminServiceTest.java
View file @
dc9df2da
...
...
@@ -8,7 +8,9 @@ import org.junit.Test;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ctrip.apollo.biz.BizTestConfiguration
;
import
com.ctrip.apollo.biz.entity.App
;
...
...
@@ -17,6 +19,8 @@ import com.ctrip.apollo.biz.entity.Namespace;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
BizTestConfiguration
.
class
)
@Transactional
@Rollback
public
class
AdminServiceTest
{
@Autowired
...
...
@@ -49,4 +53,5 @@ public class AdminServiceTest {
Assert
.
assertEquals
(
1
,
namespaces
.
size
());
Assert
.
assertEquals
(
"application"
,
namespaces
.
get
(
0
).
getNamespaceName
());
}
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/AdminServiceTransactionTest.java
0 → 100644
View file @
dc9df2da
package
com
.
ctrip
.
apollo
.
biz
.
service
;
import
java.util.Date
;
import
org.junit.After
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.annotation.Commit
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.transaction.AfterTransaction
;
import
org.springframework.test.context.transaction.BeforeTransaction
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ctrip.apollo.biz.BizTestConfiguration
;
import
com.ctrip.apollo.biz.entity.App
;
import
com.ctrip.apollo.biz.repository.AppNamespaceRepository
;
import
com.ctrip.apollo.biz.repository.AppRepository
;
import
com.ctrip.apollo.biz.repository.ClusterRepository
;
import
com.ctrip.apollo.biz.repository.NamespaceRepository
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
BizTestConfiguration
.
class
)
@Transactional
@Commit
public
class
AdminServiceTransactionTest
{
@Autowired
AdminService
adminService
;
@Autowired
private
AppRepository
appRepository
;
@Autowired
private
AppNamespaceRepository
appNamespaceRepository
;
@Autowired
private
NamespaceRepository
namespaceRepository
;
@Autowired
private
ClusterRepository
clusterRepository
;
@BeforeTransaction
public
void
verifyInitialDatabaseState
()
{
for
(
App
app
:
appRepository
.
findAll
())
{
System
.
out
.
println
(
app
.
getAppId
());
}
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
}
@Before
public
void
setUpTestDataWithinTransaction
()
{
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
}
@Test
@Rollback
public
void
modifyDatabaseWithinTransaction
()
{
String
appId
=
"someAppId"
;
App
app
=
new
App
();
app
.
setAppId
(
appId
);
app
.
setName
(
"someAppName"
);
String
owner
=
"someOwnerName"
;
app
.
setOwnerName
(
owner
);
app
.
setOwnerEmail
(
"someOwnerName@ctrip.com"
);
app
.
setDataChangeCreatedBy
(
owner
);
app
.
setDataChangeLastModifiedBy
(
owner
);
app
.
setDataChangeCreatedTime
(
new
Date
());
adminService
.
createNewApp
(
app
);
}
@After
public
void
tearDownWithinTransaction
()
{
Assert
.
assertEquals
(
1
,
appRepository
.
count
());
Assert
.
assertEquals
(
1
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
1
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
1
,
clusterRepository
.
count
());
}
@AfterTransaction
public
void
verifyFinalDatabaseState
()
{
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
}
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/PrivilegeServiceTest.java
View file @
dc9df2da
...
...
@@ -8,7 +8,9 @@ import org.junit.Test;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ctrip.apollo.biz.BizTestConfiguration
;
import
com.ctrip.apollo.biz.entity.App
;
...
...
@@ -18,6 +20,8 @@ import com.ctrip.apollo.biz.entity.Privilege;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
BizTestConfiguration
.
class
)
@Transactional
@Rollback
public
class
PrivilegeServiceTest
{
@Autowired
...
...
@@ -96,4 +100,5 @@ public class PrivilegeServiceTest {
Assert
.
assertTrue
(
privilService
.
hasPrivilege
(
namespace
.
getId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
RELEASE
));
}
}
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