@SuppressWarnings("unchecked") @Test public void isChangedメソッドでMemcachedからキャッシュを取得できた場合falseを返すこと() throws Exception { String nodeId = "nodeId"; Map<String, Object> data = new HashMap<String, Object>(); data.put("testKey", "testValue"); Constructor<MemcachedClient> c = MemcachedClient.class.getDeclaredConstructor(); c.setAccessible(true); MemcachedClient mockMemcachedClient = Mockito.spy(c.newInstance()); Mockito.doReturn(data).when(mockMemcachedClient).get(Mockito.anyString(), Mockito.any(Class.class)); PowerMockito.spy(UserDataSchemaCache.class); PowerMockito.when(UserDataSchemaCache.class, "getMcdClient").thenReturn(mockMemcachedClient); PowerMockito.spy(DcCoreConfig.class); PowerMockito.when(DcCoreConfig.class, "isSchemaCacheEnabled").thenReturn(true); boolean isChanged = UserDataSchemaCache.isChanged(nodeId, data); assertFalse(isChanged); }
@SuppressWarnings("unchecked") public static boolean isChanged(String nodeId, Map<String, Object> cache) { if (!DcCoreConfig.isSchemaCacheEnabled()) { return false; } Map<String, Object> latestCache = null; try { latestCache = getMcdClient().get(cacheKey(nodeId), Map.class); } catch (MemcachedClientException e) { log.info("Failed to get latest UserDataSchemaCache."); } if (latestCache == null) { return true; } long disabledTime = 0; if (cache.containsKey("disabledTime")) { disabledTime = (Long) cache.get("disabledTime"); } long latestDisabledTime = 0; if (latestCache.containsKey("disabledTime")) { latestDisabledTime = (Long) latestCache.get("disabledTime"); } if (disabledTime != latestDisabledTime) { return true; } return false; }
UserDataSchemaCache { @SuppressWarnings("unchecked") public static boolean isChanged(String nodeId, Map<String, Object> cache) { if (!DcCoreConfig.isSchemaCacheEnabled()) { return false; } Map<String, Object> latestCache = null; try { latestCache = getMcdClient().get(cacheKey(nodeId), Map.class); } catch (MemcachedClientException e) { log.info("Failed to get latest UserDataSchemaCache."); } if (latestCache == null) { return true; } long disabledTime = 0; if (cache.containsKey("disabledTime")) { disabledTime = (Long) cache.get("disabledTime"); } long latestDisabledTime = 0; if (latestCache.containsKey("disabledTime")) { latestDisabledTime = (Long) latestCache.get("disabledTime"); } if (disabledTime != latestDisabledTime) { return true; } return false; } }
UserDataSchemaCache { @SuppressWarnings("unchecked") public static boolean isChanged(String nodeId, Map<String, Object> cache) { if (!DcCoreConfig.isSchemaCacheEnabled()) { return false; } Map<String, Object> latestCache = null; try { latestCache = getMcdClient().get(cacheKey(nodeId), Map.class); } catch (MemcachedClientException e) { log.info("Failed to get latest UserDataSchemaCache."); } if (latestCache == null) { return true; } long disabledTime = 0; if (cache.containsKey("disabledTime")) { disabledTime = (Long) cache.get("disabledTime"); } long latestDisabledTime = 0; if (latestCache.containsKey("disabledTime")) { latestDisabledTime = (Long) latestCache.get("disabledTime"); } if (disabledTime != latestDisabledTime) { return true; } return false; } private  UserDataSchemaCache(); }
UserDataSchemaCache { @SuppressWarnings("unchecked") public static boolean isChanged(String nodeId, Map<String, Object> cache) { if (!DcCoreConfig.isSchemaCacheEnabled()) { return false; } Map<String, Object> latestCache = null; try { latestCache = getMcdClient().get(cacheKey(nodeId), Map.class); } catch (MemcachedClientException e) { log.info("Failed to get latest UserDataSchemaCache."); } if (latestCache == null) { return true; } long disabledTime = 0; if (cache.containsKey("disabledTime")) { disabledTime = (Long) cache.get("disabledTime"); } long latestDisabledTime = 0; if (latestCache.containsKey("disabledTime")) { latestDisabledTime = (Long) latestCache.get("disabledTime"); } if (disabledTime != latestDisabledTime) { return true; } return false; } private  UserDataSchemaCache(); static Map<String, Object> get(String nodeId); static void cache(String nodeId, Map<String, Object> schema); static void clear(String nodeId); static void disable(String nodeId); static boolean isDisabled(Map<String, Object> cache); @SuppressWarnings("unchecked") static boolean isChanged(String nodeId, Map<String, Object> cache); }
UserDataSchemaCache { @SuppressWarnings("unchecked") public static boolean isChanged(String nodeId, Map<String, Object> cache) { if (!DcCoreConfig.isSchemaCacheEnabled()) { return false; } Map<String, Object> latestCache = null; try { latestCache = getMcdClient().get(cacheKey(nodeId), Map.class); } catch (MemcachedClientException e) { log.info("Failed to get latest UserDataSchemaCache."); } if (latestCache == null) { return true; } long disabledTime = 0; if (cache.containsKey("disabledTime")) { disabledTime = (Long) cache.get("disabledTime"); } long latestDisabledTime = 0; if (latestCache.containsKey("disabledTime")) { latestDisabledTime = (Long) latestCache.get("disabledTime"); } if (disabledTime != latestDisabledTime) { return true; } return false; } private  UserDataSchemaCache(); static Map<String, Object> get(String nodeId); static void cache(String nodeId, Map<String, Object> schema); static void clear(String nodeId); static void disable(String nodeId); static boolean isDisabled(Map<String, Object> cache); @SuppressWarnings("unchecked") static boolean isChanged(String nodeId, Map<String, Object> cache);  }