@SuppressWarnings("unchecked") @Test public void Memcachedからキャッシュを取得できた場合オブジェクトを返すこと() throws Exception { String boxName = "boxCacheTestBox"; Map<String, Object> box = new HashMap<String, Object>(); box.put("name", boxName); box.put("schema", null); box.put("id", "boxId"); box.put("published", 1380604545159L); Constructor<MemcachedClient> c = MemcachedClient.class.getDeclaredConstructor(); c.setAccessible(true); MemcachedClient mockMemcachedClient = Mockito.spy(c.newInstance()); Mockito.doReturn(box).when(mockMemcachedClient).get(Mockito.anyString(), Mockito.any(Class.class)); PowerMockito.spy(BoxCache.class); PowerMockito.when(BoxCache.class, "getMcdClient").thenReturn(mockMemcachedClient); PowerMockito.spy(DcCoreConfig.class); PowerMockito.when(DcCoreConfig.class, "isBoxCacheEnabled").thenReturn(true); CellEsImpl cell = new CellEsImpl(); cell.setId("CellId"); Box cache = BoxCache.get(boxName, cell); assertNotNull(cache); }
public static Box get(String boxName, Cell cell) { if (!DcCoreConfig.isBoxCacheEnabled()) { return null; } @SuppressWarnings("rawtypes") HashMap obj = null; try { obj = getMcdClient().get(cacheKey(boxName, cell), HashMap.class); } catch (MemcachedClientException e) { log.info("Failed to get BoxCache."); } if (obj == null) { return null; } return new Box(cell, (String) obj.get("name"), (String) obj.get("schema"), (String) obj.get("id"), (Long) obj.get("published")); }
BoxCache { public static Box get(String boxName, Cell cell) { if (!DcCoreConfig.isBoxCacheEnabled()) { return null; } @SuppressWarnings("rawtypes") HashMap obj = null; try { obj = getMcdClient().get(cacheKey(boxName, cell), HashMap.class); } catch (MemcachedClientException e) { log.info("Failed to get BoxCache."); } if (obj == null) { return null; } return new Box(cell, (String) obj.get("name"), (String) obj.get("schema"), (String) obj.get("id"), (Long) obj.get("published")); } }
BoxCache { public static Box get(String boxName, Cell cell) { if (!DcCoreConfig.isBoxCacheEnabled()) { return null; } @SuppressWarnings("rawtypes") HashMap obj = null; try { obj = getMcdClient().get(cacheKey(boxName, cell), HashMap.class); } catch (MemcachedClientException e) { log.info("Failed to get BoxCache."); } if (obj == null) { return null; } return new Box(cell, (String) obj.get("name"), (String) obj.get("schema"), (String) obj.get("id"), (Long) obj.get("published")); } private  BoxCache(); }
BoxCache { public static Box get(String boxName, Cell cell) { if (!DcCoreConfig.isBoxCacheEnabled()) { return null; } @SuppressWarnings("rawtypes") HashMap obj = null; try { obj = getMcdClient().get(cacheKey(boxName, cell), HashMap.class); } catch (MemcachedClientException e) { log.info("Failed to get BoxCache."); } if (obj == null) { return null; } return new Box(cell, (String) obj.get("name"), (String) obj.get("schema"), (String) obj.get("id"), (Long) obj.get("published")); } private  BoxCache(); static Box get(String boxName, Cell cell); static void cache(Box box); static void clear(String boxName, Cell cell); }
BoxCache { public static Box get(String boxName, Cell cell) { if (!DcCoreConfig.isBoxCacheEnabled()) { return null; } @SuppressWarnings("rawtypes") HashMap obj = null; try { obj = getMcdClient().get(cacheKey(boxName, cell), HashMap.class); } catch (MemcachedClientException e) { log.info("Failed to get BoxCache."); } if (obj == null) { return null; } return new Box(cell, (String) obj.get("name"), (String) obj.get("schema"), (String) obj.get("id"), (Long) obj.get("published")); } private  BoxCache(); static Box get(String boxName, Cell cell); static void cache(Box box); static void clear(String boxName, Cell cell);  }