public static void main(String[] args) throws Exception { if (args.length != 3) { System.out.println("USAGE: IntegrityTest <dbName> <interval> <datatype>"); return; } String dbName = args[0]; int interval = Integer.parseInt(args[1]); String[] types = args[2].split(","); PerstPowerDB db = new PerstPowerDB(dbName, interval); db.open(); for (int i = 0; i < types.length; ++i) checkIntegrity(db, types[i], interval); db.close(); }
public static Boolean checkIntegrity(PerstPowerDB db, String loadType, int inc) throws Exception { Calendar cal = new Calendar(); Date st = cal.addSecondsTo(db.first(loadType), -inc); Date ed = db.last(loadType); System.out.println("Load starts from " + db.first(loadType) + " to " + ed); Series load = db.getLoad(loadType, st, ed); Boolean integ = true; int gapStart = -1, gapEnd = -1; for (int i = 1; i <= load.length(); ++i) { Double d = new Double(load.element(i)); if (d.equals(Double.NaN)) { if (gapStart == -1) { gapStart = i; gapEnd = i; } else ++gapEnd; integ = false; } else { if (gapStart != -1) { System.err.println( "Load from " + cal.addSecondsTo(st, gapStart * inc) + " to " + cal.addSecondsTo(st, gapEnd * inc) + " does not exist"); gapStart = -1; gapEnd = -1; } } } if (gapStart != -1) { System.err.println( "Load from " + cal.addSecondsTo(st, gapStart * inc) + " to " + cal.addSecondsTo(st, gapEnd * inc) + " does not exist"); } if (!integ) System.err.println("The database contains gaps at some points"); else System.out.println("The database contains loads from " + db.first(loadType) + " to " + ed); return integ; }