public QueryInterceptor(SearchIntegrator searchFactory, KeyTransformationHandler keyTransformationHandler, IndexModificationStrategy indexingMode, ConcurrentMap<GlobalTransaction, Map<Object, Object>> txOldValues, AdvancedCache<?, ?> cache) { this.searchFactory = searchFactory; this.keyTransformationHandler = keyTransformationHandler; this.indexingMode = indexingMode; this.txOldValues = txOldValues; this.cache = cache; this.valueDataConversion = cache.getValueDataConversion(); this.keyDataConversion = cache.getKeyDataConversion(); }
@Override public DataConversion getKeyDataConversion() { return cache.getKeyDataConversion(); }
public QueryInterceptor(SearchIntegrator searchFactory, IndexModificationStrategy indexingMode, Cache cache) { this.searchFactory = searchFactory; this.indexingMode = indexingMode; this.cache = cache; this.valueDataConversion = cache.getAdvancedCache().getValueDataConversion(); this.keyDataConversion = cache.getAdvancedCache().getKeyDataConversion(); }
@Override public void setEnvironment(Cache<Object, Object> cache, Set<Object> inputKeys) { AdvancedCache<Object, Object> unwrapped = SecurityActions.getUnwrappedCache(cache).getAdvancedCache(); if (unwrapped.getCacheConfiguration().memory().storageType() == StorageType.OBJECT) { this.cache = unwrapped.withWrapping(ByteArrayWrapper.class, IdentityWrapper.class); } else { this.cache = cache; //todo [anistor] why not `unwrapped` instead ? do we need security for mass indexing ? } SearchIntegrator searchIntegrator = ComponentRegistryUtils.getSearchIntegrator(unwrapped); KeyTransformationHandler keyTransformationHandler = ComponentRegistryUtils.getKeyTransformationHandler(unwrapped); TimeService timeService = ComponentRegistryUtils.getTimeService(unwrapped); this.indexUpdater = new IndexUpdater(searchIntegrator, keyTransformationHandler, timeService); this.clusteringDependentLogic = SecurityActions.getClusteringDependentLogic(unwrapped); if (everywhereKeys != null) keys.addAll(everywhereKeys); if (inputKeys != null) keys.addAll(inputKeys); keyDataConversion = unwrapped.getKeyDataConversion(); valueDataConversion = unwrapped.getValueDataConversion(); }
@Test(dataProvider = "capacityTest") public void testCapacity(int inserts, int nodeExpected) { caches().forEach(c -> { DataContainer container = c.getAdvancedCache().getDataContainer(); // Just reuse same value Object value = c.getAdvancedCache().getValueDataConversion().toStorage("foo"); Metadata metadata = new EmbeddedMetadata.Builder().build(); // We just insert into data container directly - as we can guarantee same size then (this can't happen // in a real cache, but we can control the size easily) for (int i = 0; i < inserts; ++i) { Object key = c.getAdvancedCache().getKeyDataConversion().toStorage(i); container.put(key, value, metadata); } }); ClusterCacheStats stats = TestingUtil.extractComponent(cache(0), ClusterCacheStats.class); assertEquals(handleModeEstimate(nodeExpected, cacheMode), stats.getRequiredMinimumNumberOfNodes()); } }
@Override public void call() throws Exception { ComponentRegistry registry = cm.getCache().getAdvancedCache().getComponentRegistry(); testWith(DataConversion.DEFAULT_KEY, registry); testWith(DataConversion.DEFAULT_VALUE, registry); testWith(DataConversion.IDENTITY_KEY, registry); testWith(DataConversion.IDENTITY_VALUE, registry); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.compatibility().enable(); cm.defineConfiguration("compat", builder.build()); AdvancedCache<?, ?> compat = cm.getCache("compat").getAdvancedCache(); ComponentRegistry compatRegistry = compat.getComponentRegistry(); testWith(compat.getKeyDataConversion(), compatRegistry); testWith(compat.getValueDataConversion(), compatRegistry); AdvancedCache<?, ?> wrapped = compat.withEncoding(IdentityEncoder.class).withWrapping(IdentityWrapper.class); ComponentRegistry wrappedRegistry = wrapped.getComponentRegistry(); testWith(wrapped.getKeyDataConversion(), wrappedRegistry); testWith(wrapped.getValueDataConversion(), wrappedRegistry); } });
@Override protected void assertOwnershipAndNonOwnership(Object key, boolean allowL1) { for (Cache cache : caches) { Object keyToBeChecked = cache.getAdvancedCache().getKeyDataConversion().toStorage(key); DataContainer dc = cache.getAdvancedCache().getDataContainer(); InternalCacheEntry ice = dc.get(keyToBeChecked); if (isOwner(cache, keyToBeChecked)) { assertNotNull(ice); assertTrue(ice instanceof ImmortalCacheEntry); } else { if (allowL1) { assertTrue("ice is null or L1Entry", ice == null || ice.isL1Entry()); } else { // Segments no longer owned are invalidated asynchronously eventuallyEquals("Fail on non-owner cache " + addressOf(cache) + ": dc.get(" + key + ")", null, () -> dc.get(keyToBeChecked)); } } } }
public void testStoreAsBinaryOnBoth() { ConfigurationBuilder c = new ConfigurationBuilder(); c.memory().storageType(StorageType.BINARY).build(); ecm = TestCacheManagerFactory.createCacheManager(c); ecm.getCache().put(key, value); DataConversion keyDataConversion = ecm.getCache().getAdvancedCache().getKeyDataConversion(); DataConversion valueDataConversion = ecm.getCache().getAdvancedCache().getValueDataConversion(); DataContainer<?, ?> dc = ecm.getCache().getAdvancedCache().getDataContainer(); InternalCacheEntry entry = dc.iterator().next(); Object key = entry.getKey(); Object value = entry.getValue(); assertTrue(key instanceof WrappedBytes); assertEquals(keyDataConversion.fromStorage(key), this.key); assertTrue(value instanceof WrappedBytes); assertEquals(valueDataConversion.fromStorage(value), this.value); } }
DataConversion dc = cache(0).getAdvancedCache().getKeyDataConversion();
Object storageKey = cache(0).getAdvancedCache().getKeyDataConversion().toStorage(expiringKey);
timeService.advance(10); DataConversion dataConversion = cache.getAdvancedCache().getKeyDataConversion();