use of com.hedera.services.bdd.spec.keys.KeyShape.listOf in project hedera-services by hashgraph.
the class FileExpansionLoadProvider method fileExpansionsFactory.
private Function<HapiApiSpec, OpProvider> fileExpansionsFactory() {
final SplittableRandom r = new SplittableRandom();
final Set<String> usableTargets = ConcurrentHashMap.newKeySet();
final LongFunction<String> targetNameFn = i -> "expandingFile" + i;
final AtomicInteger nextTargetNum = new AtomicInteger(numActiveTargets.get());
final var key = "multi";
final var waclShape = KeyShape.listOf(SIMPLE, threshOf(1, 3), listOf(2));
return spec -> new OpProvider() {
@Override
public List<HapiSpecOperation> suggestedInitializers() {
final List<HapiSpecOperation> ops = new ArrayList<>();
ops.add(newKeyNamed(key).shape(waclShape));
for (int i = 0, n = numActiveTargets.get(); i < n; i++) {
ops.add(fileCreate(targetNameFn.apply(i)).key(key).noLogging().contents(DATA_CHUNK).payingWith(GENESIS));
}
return ops;
}
@Override
public Optional<HapiSpecOperation> get() {
HapiSpecOperation op;
if (usableTargets.size() < numActiveTargets.get()) {
final var name = targetNameFn.apply(nextTargetNum.getAndIncrement());
op = fileCreate(name).noLogging().key(key).contents(DATA_CHUNK).payingWith(GENESIS).deferStatusResolution().exposingNumTo(num -> {
usableTargets.add(name);
});
} else {
final var skips = r.nextInt(usableTargets.size());
final var iter = usableTargets.iterator();
try {
for (int i = 0; i < skips; i++) {
iter.next();
}
final var target = iter.next();
op = fileAppend(target).noLogging().deferStatusResolution().payingWith(GENESIS).content(DATA_CHUNK).hasKnownStatusFrom(MAX_FILE_SIZE_EXCEEDED, SUCCESS).alertingPost(code -> {
if (code == MAX_FILE_SIZE_EXCEEDED) {
log.info("File {} reached max size, no longer in rotation", target);
usableTargets.remove(target);
}
});
} catch (Exception ignore) {
op = noOp();
}
}
return Optional.of(op);
}
};
}
Aggregations