use of com.yahoo.athenz.zms.DomainModified in project athenz by yahoo.
the class FileConnection method listModifiedDomains.
@Override
public DomainModifiedList listModifiedDomains(long modifiedSince) {
DomainModifiedList domainModifiedList = new DomainModifiedList();
List<DomainModified> nameMods = new ArrayList<DomainModified>();
List<String> domainList = listDomains(null, modifiedSince);
// Now set the dest for the returned domain names
String dirName = rootDir.getAbsolutePath() + File.separator;
for (String dname : domainList) {
long ts = 0;
try {
File dfile = new File(dirName + dname);
ts = dfile.lastModified();
if (ts <= modifiedSince) {
continue;
}
} catch (Exception exc) {
LOG.error("FileStructStore: FAILED to get timestamp for file " + dname + ", error: " + exc.getMessage());
}
DomainModified dm = new DomainModified().setName(dname).setModified(ts);
nameMods.add(dm);
}
domainModifiedList.setNameModList(nameMods);
return domainModifiedList;
}
use of com.yahoo.athenz.zms.DomainModified in project athenz by yahoo.
the class JDBCConnection method listModifiedDomains.
@Override
public DomainModifiedList listModifiedDomains(long modifiedSince) {
final String caller = "listModifiedDomains";
DomainModifiedList domainModifiedList = new DomainModifiedList();
List<DomainModified> nameMods = new ArrayList<DomainModified>();
try (PreparedStatement ps = prepareDomainScanStatement(null, modifiedSince)) {
try (ResultSet rs = executeQuery(ps, caller)) {
while (rs.next()) {
DomainModified dm = new DomainModified().setName(rs.getString(ZMSConsts.DB_COLUMN_NAME)).setModified(rs.getTimestamp(ZMSConsts.DB_COLUMN_MODIFIED).getTime());
nameMods.add(dm);
}
}
} catch (SQLException ex) {
throw sqlError(ex, caller);
}
domainModifiedList.setNameModList(nameMods);
return domainModifiedList;
}
use of com.yahoo.athenz.zms.DomainModified in project athenz by yahoo.
the class JDBCConnectionTest method testListModifiedDomains.
@Test
public void testListModifiedDomains() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
// 3 domains
Mockito.when(mockResultSet.next()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_NAME)).thenReturn("domain1").thenReturn("domain2").thenReturn(// 3 domains
"domain3");
Mockito.doReturn(new java.sql.Timestamp(1454358916)).when(mockResultSet).getTimestamp(ZMSConsts.DB_COLUMN_MODIFIED);
DomainModifiedList list = jdbcConn.listModifiedDomains(1454358900);
Mockito.verify(mockPrepStmt, times(1)).setTimestamp(Matchers.eq(1), Matchers.eq(new java.sql.Timestamp(1454358900)), Matchers.isA(Calendar.class));
assertEquals(3, list.getNameModList().size());
boolean domain1Found = false;
boolean domain2Found = false;
boolean domain3Found = false;
for (DomainModified dom : list.getNameModList()) {
switch(dom.getName()) {
case "domain1":
domain1Found = true;
break;
case "domain2":
domain2Found = true;
break;
case "domain3":
domain3Found = true;
break;
}
}
assertTrue(domain1Found);
assertTrue(domain2Found);
assertTrue(domain3Found);
jdbcConn.close();
}
Aggregations