@Test public void testBoundaries() throws Exception { if (! "/".equals(File.separator)) { return; } SlotMapper mapper = new SlotMapper(); GregorianCalendar c1; GregorianCalendar c2; c1 = new GregorianCalendar(2011,0,20,1,59,59); c2 = new GregorianCalendar(2011,0,20,2,0,0); ensureDifferent(mapper, c1, c2); ensureConsistentMapping(mapper, c1); ensureConsistentMapping(mapper, c2); assertEquals("2011/01/20/"+SERVICENAME+"_2011-01-20_01", mapper.map(c1.getTimeInMillis(), SERVICENAME)); assertEquals("2011/01/20/"+SERVICENAME+"_2011-01-20_02", mapper.map(c2.getTimeInMillis(), SERVICENAME)); c1 = new GregorianCalendar(2011,0,20,23,59,59); c2 = new GregorianCalendar(2011,0,21,0,0,0); ensureDifferent(mapper, c1, c2); ensureConsistentMapping(mapper, c1); ensureConsistentMapping(mapper, c2); assertEquals("2011/01/20/"+SERVICENAME+"_2011-01-20_23", mapper.map(c1.getTimeInMillis(), SERVICENAME)); assertEquals("2011/01/21/"+SERVICENAME+"_2011-01-21_00", mapper.map(c2.getTimeInMillis(), SERVICENAME)); c1 = new GregorianCalendar(2011,0,31,23,59,59); c2 = new GregorianCalendar(2011,1,1,0,0,0); ensureDifferent(mapper, c1, c2); ensureConsistentMapping(mapper, c1); ensureConsistentMapping(mapper, c2); assertEquals("2011/01/31/"+SERVICENAME+"_2011-01-31_23", mapper.map(c1.getTimeInMillis(), SERVICENAME)); assertEquals("2011/02/01/"+SERVICENAME+"_2011-02-01_00", mapper.map(c2.getTimeInMillis(), SERVICENAME)); c1 = new GregorianCalendar(2011,1,28,23,59,59); c2 = new GregorianCalendar(2011,2,1,0,0,0); ensureDifferent(mapper, c1, c2); ensureConsistentMapping(mapper, c1); ensureConsistentMapping(mapper, c2); assertEquals("2011/02/28/"+SERVICENAME+"_2011-02-28_23", mapper.map(c1.getTimeInMillis(), SERVICENAME)); assertEquals("2011/03/01/"+SERVICENAME+"_2011-03-01_00", mapper.map(c2.getTimeInMillis(), SERVICENAME)); c1 = new GregorianCalendar(2012,1,29,23,59,59); c2 = new GregorianCalendar(2012,2,1,0,0,0); ensureDifferent(mapper, c1, c2); ensureConsistentMapping(mapper, c1); ensureConsistentMapping(mapper, c2); assertEquals("2012/02/29/"+SERVICENAME+"_2012-02-29_23", mapper.map(c1.getTimeInMillis(), SERVICENAME)); assertEquals("2012/03/01/"+SERVICENAME+"_2012-03-01_00", mapper.map(c2.getTimeInMillis(), SERVICENAME)); c1 = new GregorianCalendar(2011,11,31,23,59,59); c2 = new GregorianCalendar(2012,0,1,0,0,0); ensureDifferent(mapper, c1, c2); ensureConsistentMapping(mapper, c1); ensureConsistentMapping(mapper, c2); assertEquals("2011/12/31/"+SERVICENAME+"_2011-12-31_23", mapper.map(c1.getTimeInMillis(), SERVICENAME)); assertEquals("2012/01/01/"+SERVICENAME+"_2012-01-01_00", mapper.map(c2.getTimeInMillis(), SERVICENAME)); }
public String map(long time, String service) { if (time < 0) { throw new IllegalArgumentException("Timestamp was less than zero"); } long slotnum = time / SLOT_LENGTH; String slot = slotCache.get(slotnum); if (null == slot) { if (slotCache.size() > LARGE_CACHE) { slotCache.clear(); } slot = mapToPath(time, service); slotCache.put(slotnum, slot); } return slot; }
SlotMapper { public String map(long time, String service) { if (time < 0) { throw new IllegalArgumentException("Timestamp was less than zero"); } long slotnum = time / SLOT_LENGTH; String slot = slotCache.get(slotnum); if (null == slot) { if (slotCache.size() > LARGE_CACHE) { slotCache.clear(); } slot = mapToPath(time, service); slotCache.put(slotnum, slot); } return slot; } }
SlotMapper { public String map(long time, String service) { if (time < 0) { throw new IllegalArgumentException("Timestamp was less than zero"); } long slotnum = time / SLOT_LENGTH; String slot = slotCache.get(slotnum); if (null == slot) { if (slotCache.size() > LARGE_CACHE) { slotCache.clear(); } slot = mapToPath(time, service); slotCache.put(slotnum, slot); } return slot; }  }
SlotMapper { public String map(long time, String service) { if (time < 0) { throw new IllegalArgumentException("Timestamp was less than zero"); } long slotnum = time / SLOT_LENGTH; String slot = slotCache.get(slotnum); if (null == slot) { if (slotCache.size() > LARGE_CACHE) { slotCache.clear(); } slot = mapToPath(time, service); slotCache.put(slotnum, slot); } return slot; }  String map(long time, String service); static String mapToPath(long time, String service); }
SlotMapper { public String map(long time, String service) { if (time < 0) { throw new IllegalArgumentException("Timestamp was less than zero"); } long slotnum = time / SLOT_LENGTH; String slot = slotCache.get(slotnum); if (null == slot) { if (slotCache.size() > LARGE_CACHE) { slotCache.clear(); } slot = mapToPath(time, service); slotCache.put(slotnum, slot); } return slot; }  String map(long time, String service); static String mapToPath(long time, String service); static final TimeZone TZ; static final long SLOT_LENGTH; static final int LARGE_CACHE; }