io.rainfall.jcache.operation.RemoveOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rainfall-jcache Show documentation
Show all versions of rainfall-jcache Show documentation
Rainfall-core is the core of the Rainfall framework
/*
* Copyright 2014 Aurélien Broszniowski
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.rainfall.jcache.operation;
import io.rainfall.AssertionEvaluator;
import io.rainfall.Configuration;
import io.rainfall.ObjectGenerator;
import io.rainfall.Operation;
import io.rainfall.SequenceGenerator;
import io.rainfall.TestException;
import io.rainfall.jcache.CacheConfig;
import io.rainfall.statistics.StatisticsHolder;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.cache.Cache;
import static io.rainfall.jcache.statistics.JCacheResult.EXCEPTION;
import static io.rainfall.jcache.statistics.JCacheResult.MISS;
import static io.rainfall.jcache.statistics.JCacheResult.REMOVE;
/**
* @author Aurelien Broszniowski
*/
public class RemoveOperation implements Operation {
@Override
public void exec(final StatisticsHolder statisticsHolder, final Map,
Configuration> configurations, final List assertions) throws TestException {
CacheConfig cacheConfig = (CacheConfig)configurations.get(CacheConfig.class);
SequenceGenerator sequenceGenerator = cacheConfig.getSequenceGenerator();
final long next = sequenceGenerator.next();
List> caches = cacheConfig.getCaches();
final ObjectGenerator keyGenerator = cacheConfig.getKeyGenerator();
for (final Cache cache : caches) {
boolean removed;
long start = statisticsHolder.getTimeInNs();
try {
removed = cache.remove(keyGenerator.generate(next));
long end = statisticsHolder.getTimeInNs();
if (removed) {
statisticsHolder.record(cache.getName(), (end - start), REMOVE);
} else {
statisticsHolder.record(cache.getName(), (end - start), MISS);
}
} catch (Exception e) {
long end = statisticsHolder.getTimeInNs();
statisticsHolder.record(cache.getName(), (end - start), EXCEPTION);
}
}
}
@Override
public List getDescription() {
return Arrays.asList("remove(key)");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy