@Test public void testSetDateReturnsIndexNameWithGivenDate() { Date now = new Date(); SimpleDateFormat today = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); SimpleDateFormat todayDate = new SimpleDateFormat("yyyy-MM-dd"); RelatedItem product = new RelatedItem("1".toCharArray(),today.format(now),null,new RelatedItemAdditionalProperties()); try { Thread.sleep(2000); } catch(Exception e) { } RelatedItem product2 = new RelatedItem("1".toCharArray(),today.format(now),null,new RelatedItemAdditionalProperties()); String name = cachingDayBasedMapper.getLocationName(product); String name2 = cachingDayBasedMapper.getLocationName(product2); assertEquals(cachingDayConfig.getStorageIndexNamePrefix() + "-" + todayDate.format(new Date()),name); assertEquals(cachingDayConfig.getStorageIndexNamePrefix() + "-" + todayDate.format(new Date()),name2); product = new RelatedItem("1".toCharArray(),today.format(now),null,new RelatedItemAdditionalProperties()); try { Thread.sleep(2000); } catch(Exception e) { } product2 = new RelatedItem("1".toCharArray(),today.format(now),null,new RelatedItemAdditionalProperties()); name = nonCachingDayBasedMapper.getLocationName(product); name2 = nonCachingDayBasedMapper.getLocationName(product2); assertEquals(noncachingDayConfig.getStorageIndexNamePrefix() + "-" + todayDate.format(new Date()),name); assertEquals(noncachingDayConfig.getStorageIndexNamePrefix() + "-" + todayDate.format(new Date()),name2); RelatedItem product3 = new RelatedItem("1".toCharArray(),"1920-01-02T23:59:59+00:00",null,new RelatedItemAdditionalProperties()); name = nonCachingDayBasedMapper.getLocationName(product3); assertEquals(noncachingDayConfig.getStorageIndexNamePrefix() + "-1920-01-02",name); }
@Override public String getLocationName(RelatedItem product) { String dateStr = product.getDate(); String date; if(dateStr==null) { date = currentDayFormatter.getCurrentDay(); } else { date = currentDayFormatter.parseToDate(dateStr); } if(dateCachingEnabled) { String cachedIndexName = dayCache.get(date); if(cachedIndexName==null) { StringBuilder indexName = new StringBuilder(indexNameSize); String theIndexName = indexName.append(this.indexPrefixName).append(date).toString(); String previous = dayCache.putIfAbsent(date,theIndexName); if(previous!=null) { return previous; } else { return theIndexName; } } else { return cachedIndexName; } } else { StringBuilder indexName = new StringBuilder(indexNameSize); return indexName.append(this.indexPrefixName).append(date).toString(); } }
DayBasedStorageLocationMapper implements RelatedItemStorageLocationMapper { @Override public String getLocationName(RelatedItem product) { String dateStr = product.getDate(); String date; if(dateStr==null) { date = currentDayFormatter.getCurrentDay(); } else { date = currentDayFormatter.parseToDate(dateStr); } if(dateCachingEnabled) { String cachedIndexName = dayCache.get(date); if(cachedIndexName==null) { StringBuilder indexName = new StringBuilder(indexNameSize); String theIndexName = indexName.append(this.indexPrefixName).append(date).toString(); String previous = dayCache.putIfAbsent(date,theIndexName); if(previous!=null) { return previous; } else { return theIndexName; } } else { return cachedIndexName; } } else { StringBuilder indexName = new StringBuilder(indexNameSize); return indexName.append(this.indexPrefixName).append(date).toString(); } } }
DayBasedStorageLocationMapper implements RelatedItemStorageLocationMapper { @Override public String getLocationName(RelatedItem product) { String dateStr = product.getDate(); String date; if(dateStr==null) { date = currentDayFormatter.getCurrentDay(); } else { date = currentDayFormatter.parseToDate(dateStr); } if(dateCachingEnabled) { String cachedIndexName = dayCache.get(date); if(cachedIndexName==null) { StringBuilder indexName = new StringBuilder(indexNameSize); String theIndexName = indexName.append(this.indexPrefixName).append(date).toString(); String previous = dayCache.putIfAbsent(date,theIndexName); if(previous!=null) { return previous; } else { return theIndexName; } } else { return cachedIndexName; } } else { StringBuilder indexName = new StringBuilder(indexNameSize); return indexName.append(this.indexPrefixName).append(date).toString(); } } DayBasedStorageLocationMapper(Configuration configuration,
                                         UTCCurrentDateFormatter dateFormatter); }
DayBasedStorageLocationMapper implements RelatedItemStorageLocationMapper { @Override public String getLocationName(RelatedItem product) { String dateStr = product.getDate(); String date; if(dateStr==null) { date = currentDayFormatter.getCurrentDay(); } else { date = currentDayFormatter.parseToDate(dateStr); } if(dateCachingEnabled) { String cachedIndexName = dayCache.get(date); if(cachedIndexName==null) { StringBuilder indexName = new StringBuilder(indexNameSize); String theIndexName = indexName.append(this.indexPrefixName).append(date).toString(); String previous = dayCache.putIfAbsent(date,theIndexName); if(previous!=null) { return previous; } else { return theIndexName; } } else { return cachedIndexName; } } else { StringBuilder indexName = new StringBuilder(indexNameSize); return indexName.append(this.indexPrefixName).append(date).toString(); } } DayBasedStorageLocationMapper(Configuration configuration,
                                         UTCCurrentDateFormatter dateFormatter); @Override String getLocationName(RelatedItem product); }
DayBasedStorageLocationMapper implements RelatedItemStorageLocationMapper { @Override public String getLocationName(RelatedItem product) { String dateStr = product.getDate(); String date; if(dateStr==null) { date = currentDayFormatter.getCurrentDay(); } else { date = currentDayFormatter.parseToDate(dateStr); } if(dateCachingEnabled) { String cachedIndexName = dayCache.get(date); if(cachedIndexName==null) { StringBuilder indexName = new StringBuilder(indexNameSize); String theIndexName = indexName.append(this.indexPrefixName).append(date).toString(); String previous = dayCache.putIfAbsent(date,theIndexName); if(previous!=null) { return previous; } else { return theIndexName; } } else { return cachedIndexName; } } else { StringBuilder indexName = new StringBuilder(indexNameSize); return indexName.append(this.indexPrefixName).append(date).toString(); } } DayBasedStorageLocationMapper(Configuration configuration,
                                         UTCCurrentDateFormatter dateFormatter); @Override String getLocationName(RelatedItem product);  }