IpfixCachingServiceImpl implements IpfixCachingService { @Override public void cacheTemplateRecord(long obsvDomain, String hostname, Map<Integer, AbstractTemplateRecord> templateByIdCache) { if (templateByIdCache == null || templateByIdCache.isEmpty()) { return; } String prefix = buildCacheKey(obsvDomain, hostname); templateByIdCache.forEach((templateId, templateRecord) -> { m_ipfixTemplateRecordCache.put(new Element(buildCacheKey(prefix, templateId), templateRecord)); }); } IpfixCachingServiceImpl(); @Override void cleanUpCache(); void destroy(); void setCentralCacheManager(CacheManager centralCacheManager); void initialize(); @Override void cacheTemplateRecord(long obsvDomain, String hostname, Map<Integer, AbstractTemplateRecord> templateByIdCache); @Override AbstractTemplateRecord getTemplateRecord(long obsvDomain, String hostname, int templateId); @Override Set<String> getAllCacheKeys(); @Override void updateHostName(long obsvDomain, String oldHostName, String newHostName); @Override void cacheIpfixDataSet(long obsvDomain, String hostName, IpfixDataSet set); @Override List<IpfixDataSet> getAndInvalidateIpfixDataSet(long obsvDomain, String hostName); public Cache m_ipfixDataSetCache; public Cache m_ipfixTemplateRecordCache; }
@Test public void testCacheTemplateRecord() throws Exception { long obsvDomain = 4335L; String hostname = "deviceA"; IpfixTemplateRecord expected = generateTemplateRecord("01030002000800048008000500000E91"); IpfixTemplateRecord tr = generateTemplateRecord("01010002000800048008000500000E91"); HashMap<Integer, AbstractTemplateRecord> templateByIdCache = new HashMap<>(); templateByIdCache.put(259, expected); templateByIdCache.put(257, tr); m_ipfixfeCachingService.cacheTemplateRecord(obsvDomain, hostname, templateByIdCache); IpfixTemplateRecord tmplRecord11 = generateTemplateRecord("01030002000800048008000500000E91"); IpfixTemplateRecord tmplRecord12 = generateTemplateRecord("01010002000800048008000500000E91"); HashMap<Integer, AbstractTemplateRecord> tmplRecordByIdCache1 = new HashMap<>(); templateByIdCache.put(259, tmplRecord11); templateByIdCache.put(257, tmplRecord12); m_ipfixfeCachingService.cacheTemplateRecord(obsvDomain, "ANV1.ONT2", tmplRecordByIdCache1); IpfixTemplateRecord tmplRecord21 = generateTemplateRecord("01030002000800048008000500000E91"); IpfixTemplateRecord tmplRecord22 = generateTemplateRecord("01010002000800048008000500000E91"); HashMap<Integer, AbstractTemplateRecord> tmplRecordByIdCache2 = new HashMap<>(); templateByIdCache.put(259, tmplRecord21); templateByIdCache.put(257, tmplRecord22); m_ipfixfeCachingService.cacheTemplateRecord(obsvDomain, "ANV1.ONT3", tmplRecordByIdCache2); IpfixTemplateRecord template = (IpfixTemplateRecord) m_ipfixfeCachingService.getTemplateRecord(obsvDomain, hostname, 259); assertTemplateRecord(expected, template); template = (IpfixTemplateRecord) m_ipfixfeCachingService.getTemplateRecord(obsvDomain, hostname, 257); assertTemplateRecord(tr, template); Set<String> allCacheKeys = m_ipfixfeCachingService.getAllCacheKeys(); assertEquals(2, allCacheKeys.size()); assertTrue(allCacheKeys.contains("4335_deviceA_259")); assertTrue(allCacheKeys.contains("4335_deviceA_257")); String newHostname = "deviceA.New"; m_ipfixfeCachingService.updateHostName(obsvDomain, hostname, newHostname); template = (IpfixTemplateRecord) m_ipfixfeCachingService.getTemplateRecord(obsvDomain, newHostname, 257); assertTemplateRecord(tr, template); allCacheKeys = m_ipfixfeCachingService.getAllCacheKeys(); assertEquals(2, allCacheKeys.size()); assertTrue(allCacheKeys.contains("4335_deviceA.New_259")); assertTrue(allCacheKeys.contains("4335_deviceA.New_257")); }