public void testClone() { LRUMap map = new LRUMap(10); map.put("1", "1"); Map cloned = (Map) map.clone(); assertEquals(map.size(), cloned.size()); assertSame(map.get("1"), cloned.get("1")); }
assertEquals(2, map.maxSize()); map.put(keys[0], values[0]); assertEquals(1, map.size()); assertEquals(false, map.isFull()); assertEquals(2, map.maxSize()); map.put(keys[1], values[1]); assertEquals(2, map.size()); assertEquals(true, map.isFull()); assertSame(values[1], it.next()); map.put(keys[2], values[2]); assertEquals(2, map.size()); assertEquals(true, map.isFull()); assertSame(values[2], it.next()); map.put(keys[2], values[0]); assertEquals(2, map.size()); assertEquals(true, map.isFull()); assertSame(values[0], it.next()); map.put(keys[1], values[3]); assertEquals(2, map.size()); assertEquals(true, map.isFull());
public void testInternalState_getEntry_int() { if (isPutAddSupported() == false || isPutChangeSupported() == false) return; SingleHashCode one = new SingleHashCode("1"); SingleHashCode two = new SingleHashCode("2"); SingleHashCode three = new SingleHashCode("3"); SingleHashCode four = new SingleHashCode("4"); SingleHashCode five = new SingleHashCode("5"); SingleHashCode six = new SingleHashCode("6"); LRUMap map = new LRUMap(3, 1.0f); int hashIndex = map.hashIndex(map.hash(one), 4); map.put(one, "A"); map.put(two, "B"); map.put(three, "C"); assertEquals(one, map.getEntry(0).key); assertEquals(two, map.getEntry(1).key); assertEquals(three, map.getEntry(2).key); try { map.getEntry(-1); fail(); } catch (IndexOutOfBoundsException ex) {} try { map.getEntry(3); fail(); } catch (IndexOutOfBoundsException ex) {} }
map.put(one, "A"); map.put(two, "B"); map.put(three, "C"); assertEquals(one, map.data[hashIndex].next.next.key); map.put(four, "D"); // reuses last in next list assertEquals(two, map.data[hashIndex].next.next.key); map.put(five, "E"); // reuses last in next list assertEquals(three, map.data[hashIndex].next.next.key); map.put(six, "F"); // reuses middle in next list
try { colVis = new ColumnVisibility(visibility.toArray()); parsedVisibilitiesCache.put(visibility, Boolean.TRUE); } catch (BadArgumentException e) { log.error("Parse error after transformation : {}", visibility); parsedVisibilitiesCache.put(visibility, Boolean.FALSE); if (scanning) { return false; colVis = new ColumnVisibility(visibility.toArray()); visible = ve.evaluate(colVis); visibleCache.put(visibility, visible); } catch (VisibilityParseException | BadArgumentException e) { log.error("Parse Error", e);
problemReports.put(pr, System.currentTimeMillis());
@Override protected boolean accept(Key k, Value v) { ByteSequence testVis = k.getColumnVisibilityData(); if (testVis.length() == 0 && defaultVisibility.length() == 0) return true; else if (testVis.length() == 0) testVis = defaultVisibility; Boolean b = (Boolean) cache.get(testVis); if (b != null) return b; try { Boolean bb = ve.evaluate(new ColumnVisibility(testVis.toArray())); cache.put(testVis, bb); return bb; } catch (VisibilityParseException e) { log.error("VisibilityParseException with visibility of Key: {}", k, e); return false; } catch (BadArgumentException e) { log.error("BadArgumentException with visibility of Key: {}", k, e); return false; } }
/** * Append the key and value to the last locality group that was started. If no locality group was * started, then the default group will automatically be started. * * @param key * This key must be greater than or equal to the last key appended. For non-default * locality groups, the keys column family must be one of the column families specified * when calling startNewLocalityGroup(). Must be non-null. * @param val * value to append, must be non-null. * * @throws IllegalArgumentException * This is thrown when data is appended out of order OR when the key contains a invalid * visibility OR when a column family is not valid for a locality group. */ public void append(Key key, Value val) throws IOException { if (!startedLG) { startDefaultLocalityGroup(); } Boolean wasChecked = (Boolean) validVisibilities.get(key.getColumnVisibilityData()); if (wasChecked == null) { byte[] cv = key.getColumnVisibilityData().toArray(); new ColumnVisibility(cv); validVisibilities.put(new ArrayByteSequence(Arrays.copyOf(cv, cv.length)), Boolean.TRUE); } writer.append(key, val); }
/** * Registers a list of snapshots with internal cache, using a String key. */ public synchronized void cacheSnapshots(String key, List snapshots) { snapshotLists.put(key, snapshots); }
/** * Registers a list of snapshots with internal cache, using a String key. */ public synchronized void cacheSnapshots(String key, List snapshots) { snapshotLists.put(key, snapshots); }
public void store (int taxid, NewtResponse response) { lru.put (taxid+"", response); }
/** * Add an entry to the principal cache. * * @param principal to be cached. */ protected synchronized void addToCache(Principal principal) { cache.put(principal.getName(), principal); }
/** * Add an entry to the principal cache. * * @param principal to be cached. */ protected synchronized void addToCache(Principal principal) { cache.put(principal.getName(), principal); }
private static void cacheMisconfiguredHost(String host, int port, InetAddress address) { synchronized (misconfiguredHosts) { if (!misconfiguredHosts.isEmpty()) { removeStaleCachedMisconfiguredHosts(); } logger.info("Caching address of misconfigured (\"unrecognized_name\") host [host=" + host + ", port=" + port + "] for the next " + MAX_AGE_MISCONFIGURED_HOST_IN_MIN + " minutes, following connections will not use the hostname."); misconfiguredHosts.put(host + port, new MisconfiguredHostCacheEntry(host, port, address)); } }
public JoinEdge cacheEdge(JoinEdge edge) { edgeCache.put(new Pair<JoinVertex, JoinVertex>(edge.getLeftVertex(), edge.getRightVertex()), edge); return edge; }
public JoinEdge cacheEdge(JoinEdge edge) { edgeCache.put(new Pair<>(edge.getLeftVertex(), edge.getRightVertex()), edge); return edge; }
@Test public void testConvertToPentahoUserDisableCache() throws RepositoryException { AbstractJcrBackedUserRoleDao abstractJcrBackedUserRoleDaoMock = mock( AbstractJcrBackedUserRoleDao.class ); doCallRealMethod().when( abstractJcrBackedUserRoleDaoMock ).convertToPentahoUser( any( User.class ) ); ITenantedPrincipleNameResolver resolverMock = mock( ITenantedPrincipleNameResolver.class ); when( abstractJcrBackedUserRoleDaoMock.getTenantedUserNameUtils() ).thenReturn( resolverMock ); //Cache mocking LRUMap cacheMock = mock( LRUMap.class ); when( abstractJcrBackedUserRoleDaoMock.getUserCache() ).thenReturn( cacheMock ); User userMock = mock( User.class ); abstractJcrBackedUserRoleDaoMock.convertToPentahoUser( userMock ); verify( cacheMock, never() ).put( anyObject(), anyString() ); }
@Test public void testConvertToPentahoUserEnableCache() throws RepositoryException { AbstractJcrBackedUserRoleDao abstractJcrBackedUserRoleDaoMock = mock( AbstractJcrBackedUserRoleDao.class ); doCallRealMethod().when( abstractJcrBackedUserRoleDaoMock ).convertToPentahoUser( any( User.class ) ); ITenantedPrincipleNameResolver resolverMock = mock( ITenantedPrincipleNameResolver.class ); when( abstractJcrBackedUserRoleDaoMock.getTenantedUserNameUtils() ).thenReturn( resolverMock ); when( abstractJcrBackedUserRoleDaoMock.isUseJackrabbitUserCache() ).thenReturn( true ); //Cache mocking LRUMap cacheMock = mock( LRUMap.class ); when( abstractJcrBackedUserRoleDaoMock.getUserCache() ).thenReturn( cacheMock ); User userMock = mock( User.class ); abstractJcrBackedUserRoleDaoMock.convertToPentahoUser( userMock ); verify( cacheMock ).put( anyObject(), anyString() ); }
public static void updateCursor(String cursor, Object object) { ObjectHolder objectHolder = new ObjectHolder(object); cursors.put(cursor, objectHolder.getId()); }