use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecutePutGroupReviewRetry.
@Test
public void testExecutePutGroupReviewRetry() {
final String domainName = "group-review-retry";
List<String> admins = new ArrayList<>();
admins.add(adminUser);
Timestamp thirtyDayExpiry = Timestamp.fromMillis(System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(30, TimeUnit.DAYS) + TimeUnit.MILLISECONDS.convert(2, TimeUnit.MINUTES));
zms.dbService.makeDomain(mockDomRsrcCtx, ZMSTestUtils.makeDomainObject(domainName, "test desc", "org", false, "", 1234, "", 0), admins, null, auditRef);
Group group1 = createGroupObject(domainName, "group1", "user.john", "user.jane");
Timestamp timExpiry = Timestamp.fromMillis(System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(10, TimeUnit.DAYS));
group1.getGroupMembers().add(new GroupMember().setMemberName("user.tim").setExpiration(timExpiry).setApproved(true).setActive(true));
zms.dbService.executePutGroup(mockDomRsrcCtx, domainName, "group1", group1, "putgroup");
Group incomingGroup = new Group().setName("group1");
List<GroupMember> incomingMembers = new ArrayList<>();
incomingMembers.add(new GroupMember().setMemberName("user.john").setActive(false).setExpiration(thirtyDayExpiry).setPrincipalType(Principal.Type.USER.getValue()));
incomingMembers.add(new GroupMember().setMemberName("user.jane").setActive(true).setExpiration(thirtyDayExpiry).setPrincipalType(Principal.Type.USER.getValue()));
incomingGroup.setGroupMembers(incomingMembers);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
int saveRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 2;
ObjectStoreConnection mockConn = Mockito.mock(ObjectStoreConnection.class);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockConn);
Mockito.when(mockConn.getDomain(domainName)).thenThrow(new ResourceException(ResourceException.CONFLICT));
MemberDueDays expiryDueDays = new MemberDueDays(new Domain(), new Group().setMemberExpiryDays(10));
try {
zms.dbService.executePutGroupReview(mockDomRsrcCtx, domainName, "group1", incomingGroup, expiryDueDays, "review test");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.CONFLICT);
}
// getDomain gets called to check domain auditEnabled requirement. verification of 2 retries happened
verify(mockConn, times(2)).getDomain(domainName);
zms.dbService.store = saveStore;
zms.dbService.defaultRetryCount = saveRetryCount;
Group resGroup = zms.dbService.getGroup(domainName, "group1", false, false);
assertEquals(resGroup.getGroupMembers().size(), 3);
int membersChecked = 0;
for (GroupMember groupMember : resGroup.getGroupMembers()) {
switch(groupMember.getMemberName()) {
case "user.john":
case "user.jane":
assertNull(groupMember.getExpiration());
assertTrue(groupMember.getApproved());
membersChecked += 1;
break;
case "user.tim":
assertEquals(groupMember.getExpiration(), timExpiry);
membersChecked += 1;
break;
}
}
assertEquals(membersChecked, 3);
zms.dbService.executeDeleteDomain(mockDomRsrcCtx, domainName, auditRef, "deletedomain");
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testPutDomainDependencyRetryFailure.
@Test
public void testPutDomainDependencyRetryFailure() {
String domainName = "putDomainDependencyRetryFail1";
String serviceName = "service1";
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.insertDomainDependency(eq(domainName), eq(serviceName))).thenThrow(new ResourceException(ResourceException.CONFLICT));
Domain domain = new Domain().setName(domainName);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
int saveRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 2;
try {
zms.dbService.putDomainDependency(mockDomRsrcCtx, domainName, serviceName, auditRef, "putDomainDependency");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.CONFLICT);
}
zms.dbService.defaultRetryCount = saveRetryCount;
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecutePutServiceIdentityFailure.
@Test
public void testExecutePutServiceIdentityFailure() {
String domainName = "serviceadddom1";
String serviceName = "service1";
ServiceIdentity service = createServiceObject(domainName, serviceName, "http://localhost", "/usr/bin/java", "root", "users", "host1");
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.insertServiceIdentity(anyString(), any(ServiceIdentity.class))).thenReturn(false);
Domain domain = new Domain().setName(domainName);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
try {
zms.dbService.executePutServiceIdentity(mockDomRsrcCtx, domainName, serviceName, service, auditRef, "putServiceIdentity");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.INTERNAL_SERVER_ERROR);
}
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecuteDeleteEntityFailureRetry.
@Test
public void testExecuteDeleteEntityFailureRetry() {
String domainName = "entitydelete1";
String entityName = "entity1";
Domain domain = new Domain().setAuditEnabled(false);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
Mockito.when(mockJdbcConn.deleteEntity(domainName, entityName)).thenThrow(new ResourceException(ResourceException.CONFLICT, "conflict"));
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
int saveRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 2;
try {
zms.dbService.executeDeleteEntity(mockDomRsrcCtx, domainName, entityName, auditRef, "deleteEntity");
fail();
} catch (ResourceException ex) {
assertEquals(ResourceException.CONFLICT, ex.getCode());
}
zms.dbService.defaultRetryCount = saveRetryCount;
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testGetRoleReviewMembersFailure.
@Test
public void testGetRoleReviewMembersFailure() {
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
ObjectStoreConnection mockConn = Mockito.mock(ObjectStoreConnection.class);
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockConn);
Mockito.when(mockConn.updateRoleMemberReviewNotificationTimestamp(anyString(), anyLong(), anyInt())).thenReturn(false);
assertNull(zms.dbService.getRoleReviewMembers(1));
zms.dbService.store = saveStore;
}
Aggregations