Search in sources :

Example 1 with HapiGetFileContents

use of com.hedera.services.bdd.spec.queries.file.HapiGetFileContents in project hedera-services by hashgraph.

the class HapiFileUpdate method readBaseProps.

private ServicesConfigurationList readBaseProps(HapiApiSpec spec) {
    if (dropUnmentionedProperties) {
        return ServicesConfigurationList.getDefaultInstance();
    }
    if (!basePropsFile.isPresent()) {
        if (!file.equals(HapiApiSuite.API_PERMISSIONS) && !file.equals(HapiApiSuite.APP_PROPERTIES)) {
            throw new IllegalStateException("Property overrides make no sense for file '" + file + "'!");
        }
        int getsRemaining = 10;
        var gotFileContents = false;
        HapiGetFileContents subOp = null;
        while (!gotFileContents) {
            try {
                var candSubOp = getFileContents(file);
                payer.ifPresent(name -> candSubOp.payingWith(payerToUse(name, spec)));
                allRunFor(spec, candSubOp);
                gotFileContents = true;
                subOp = candSubOp;
            } catch (Throwable ignore) {
                getsRemaining--;
            }
            if (getsRemaining == 0) {
                break;
            }
        }
        if (!gotFileContents) {
            Assertions.fail("Unable to use 'overridingProps', couldn't get existing file contents!");
        }
        try {
            byte[] bytes = subOp.getResponse().getFileGetContents().getFileContents().getContents().toByteArray();
            ServicesConfigurationList defaults = ServicesConfigurationList.parseFrom(bytes);
            return defaults;
        } catch (Exception e) {
            log.error("No available defaults for " + file + " --- aborting!", e);
            throw new IllegalStateException("Property overrides via fileUpdate must have available defaults!");
        }
    } else {
        String defaultsPath = basePropsFile.get();
        try {
            byte[] bytes = java.nio.file.Files.readAllBytes(new File(defaultsPath).toPath());
            ServicesConfigurationList defaults = ServicesConfigurationList.parseFrom(bytes);
            return defaults;
        } catch (Exception e) {
            log.error("No available defaults for " + file + " --- aborting!", e);
            throw new IllegalStateException("Property overrides via fileUpdate must have available defaults!");
        }
    }
}
Also used : ServicesConfigurationList(com.hederahashgraph.api.proto.java.ServicesConfigurationList) ByteString(com.google.protobuf.ByteString) HapiGetFileContents(com.hedera.services.bdd.spec.queries.file.HapiGetFileContents) File(java.io.File)

Example 2 with HapiGetFileContents

use of com.hedera.services.bdd.spec.queries.file.HapiGetFileContents in project hedera-services by hashgraph.

the class ProtectedFilesUpdateSuite method propertyFileValidationOp.

private HapiSpecOperation propertyFileValidationOp(String account, String fileName, String property, String expected) {
    return UtilVerbs.withOpContext((spec, ctxLog) -> {
        String registryEntry = fileName + "_CHANGED_BY_" + account;
        HapiGetFileContents subOp = getFileContents(fileName).saveToRegistry(registryEntry);
        CustomSpecAssert.allRunFor(spec, subOp);
        String newContents = new String(spec.registry().getBytes(registryEntry));
        int propertyIndex = newContents.indexOf(property);
        Assertions.assertTrue(propertyIndex >= 0);
        int valueIndex = propertyIndex + property.length() + PROPERTY_VALUE_SPACE_LENGTH;
        String actual = newContents.substring(valueIndex, valueIndex + expected.length());
        Assertions.assertEquals(expected, actual);
    });
}
Also used : ByteString(com.google.protobuf.ByteString) HapiGetFileContents(com.hedera.services.bdd.spec.queries.file.HapiGetFileContents)

Example 3 with HapiGetFileContents

use of com.hedera.services.bdd.spec.queries.file.HapiGetFileContents in project hedera-services by hashgraph.

the class RecordStreamVerification method downloadBook.

private NodeAddressBook downloadBook(HapiApiSpec spec) throws Exception {
    String addressBook = spec.setup().nodeDetailsName();
    HapiGetFileContents op = getFileContents(addressBook);
    allRunFor(spec, op);
    byte[] serializedBook = op.getResponse().getFileGetContents().getFileContents().getContents().toByteArray();
    return NodeAddressBook.parseFrom(serializedBook);
}
Also used : HapiGetFileContents(com.hedera.services.bdd.spec.queries.file.HapiGetFileContents)

Aggregations

HapiGetFileContents (com.hedera.services.bdd.spec.queries.file.HapiGetFileContents)3 ByteString (com.google.protobuf.ByteString)2 ServicesConfigurationList (com.hederahashgraph.api.proto.java.ServicesConfigurationList)1 File (java.io.File)1