Search in sources :

Example 1 with MAX_FILE_SIZE_EXCEEDED

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_FILE_SIZE_EXCEEDED 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);
        }
    };
}
Also used : UtilVerbs.overriding(com.hedera.services.bdd.spec.utilops.UtilVerbs.overriding) UtilVerbs.runWithProvider(com.hedera.services.bdd.spec.utilops.UtilVerbs.runWithProvider) MINUTES(java.util.concurrent.TimeUnit.MINUTES) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) KeyShape.listOf(com.hedera.services.bdd.spec.keys.KeyShape.listOf) PerfUtilOps.stdMgmtOf(com.hedera.services.bdd.suites.perf.PerfUtilOps.stdMgmtOf) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TxnVerbs.fileAppend(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileAppend) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) SplittableRandom(java.util.SplittableRandom) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) MAX_FILE_SIZE_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_FILE_SIZE_EXCEEDED) LongFunction(java.util.function.LongFunction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) KeyShape.threshOf(com.hedera.services.bdd.spec.keys.KeyShape.threshOf) TimeUnit(java.util.concurrent.TimeUnit) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) AtomicLong(java.util.concurrent.atomic.AtomicLong) UtilVerbs.noOp(com.hedera.services.bdd.spec.utilops.UtilVerbs.noOp) List(java.util.List) HapiSpecSetup.getDefaultNodeProps(com.hedera.services.bdd.spec.HapiSpecSetup.getDefaultNodeProps) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Logger(org.apache.logging.log4j.Logger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) Optional(java.util.Optional) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) BYTES_4K(com.hedera.services.bdd.spec.transactions.TxnUtils.BYTES_4K) PerfUtilOps.mgmtOfIntProp(com.hedera.services.bdd.suites.perf.PerfUtilOps.mgmtOfIntProp) ArrayList(java.util.ArrayList) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) SplittableRandom(java.util.SplittableRandom)

Aggregations

HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 HapiSpecOperation (com.hedera.services.bdd.spec.HapiSpecOperation)1 HapiSpecSetup.getDefaultNodeProps (com.hedera.services.bdd.spec.HapiSpecSetup.getDefaultNodeProps)1 OpProvider (com.hedera.services.bdd.spec.infrastructure.OpProvider)1 KeyShape (com.hedera.services.bdd.spec.keys.KeyShape)1 SIMPLE (com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE)1 KeyShape.listOf (com.hedera.services.bdd.spec.keys.KeyShape.listOf)1 KeyShape.threshOf (com.hedera.services.bdd.spec.keys.KeyShape.threshOf)1 TxnUtils (com.hedera.services.bdd.spec.transactions.TxnUtils)1 BYTES_4K (com.hedera.services.bdd.spec.transactions.TxnUtils.BYTES_4K)1 TxnVerbs.fileAppend (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileAppend)1 TxnVerbs.fileCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate)1 UtilVerbs.newKeyNamed (com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed)1 UtilVerbs.noOp (com.hedera.services.bdd.spec.utilops.UtilVerbs.noOp)1 UtilVerbs.overriding (com.hedera.services.bdd.spec.utilops.UtilVerbs.overriding)1 UtilVerbs.runWithProvider (com.hedera.services.bdd.spec.utilops.UtilVerbs.runWithProvider)1 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)1 PerfUtilOps.mgmtOfIntProp (com.hedera.services.bdd.suites.perf.PerfUtilOps.mgmtOfIntProp)1 PerfUtilOps.stdMgmtOf (com.hedera.services.bdd.suites.perf.PerfUtilOps.stdMgmtOf)1 MAX_FILE_SIZE_EXCEEDED (com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_FILE_SIZE_EXCEEDED)1