Search in sources :

Example 6 with Config

use of com.icodici.universa.node2.Config in project universa by UniversaBlockchain.

the class JarNetworkTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    String nodeUrl = "http://node-1-pro.utoken.io:8080";
    String dbUrl = "jdbc:postgresql://localhost:15432/universa_node?user=universa&password=fuSleaphs8";
    tunnelProcess = Runtime.getRuntime().exec("ssh -N -L 15432:127.0.0.1:5432 deploy@dd.node-1-pro.utoken.io -p 54324");
    int attempts = 10;
    while (true) {
        Thread.sleep(500);
        try {
            ledger = new PostgresLedger(dbUrl);
            break;
        } catch (Exception e) {
            if (attempts-- <= 0) {
                throw e;
            }
        }
    }
    PrivateKey clientKey = TestKeys.privateKey(0);
    whiteClient = new Client(nodeUrl, clientKey, null, false);
    normalClient = new Client(nodeUrl, new PrivateKey(2048), null, false);
    paymentContract = Contract.fromPackedTransaction(Base64.decodeLines(uno_flint004_rev1_bin_b64));
    paymentContractPrivKey = new PrivateKey(Base64.decodeLines(uno_flint004_privKey_b64));
    for (int i = 0; i < NODES_COUNT; i++) {
        normalClients.add(new Client("http://node-" + (i + 1) + "-pro.utoken.io:8080", new PrivateKey(2048), null));
    }
    config = new Config();
    config.setConsensusConfigUpdater((config, n) -> {
        // Until we fix the announcer
        int negative = (int) Math.ceil(n * 0.11);
        if (negative < 1)
            negative = 1;
        int positive = (int) Math.floor(n * 0.90);
        if (negative + positive == n)
            negative += 1;
        int resyncBreak = (int) Math.ceil(n * 0.2);
        if (resyncBreak < 1)
            resyncBreak = 1;
        if (resyncBreak + positive == n)
            resyncBreak += 1;
        config.setPositiveConsensus(positive);
        config.setNegativeConsensus(negative);
        config.setResyncBreakConsensus(resyncBreak);
    });
    config.updateConsensusConfig(NODES_COUNT);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) Client(com.icodici.universa.node2.network.Client) BeforeClass(org.junit.BeforeClass)

Example 7 with Config

use of com.icodici.universa.node2.Config in project mdsal by opendaylight.

the class TracingBrokerTest method testPrintOpenTransactions.

@Test
// Finding resource leaks is the point of this test
@SuppressWarnings({ "resource", "unused" })
public void testPrintOpenTransactions() {
    DOMDataBroker domDataBroker = mock(DOMDataBroker.class, RETURNS_DEEP_STUBS);
    Config config = new ConfigBuilder().setTransactionDebugContextEnabled(true).build();
    BindingCodecTree codec = mock(BindingCodecTree.class);
    TracingBroker tracingBroker = new TracingBroker(domDataBroker, config, codec);
    for (int i = 0; i < 3; i++) {
        DOMDataTreeReadWriteTransaction tx = tracingBroker.newReadWriteTransaction();
    }
    DOMDataTreeReadWriteTransaction anotherTx = tracingBroker.newReadWriteTransaction();
    DOMTransactionChain txChain = tracingBroker.createTransactionChain(null);
    DOMDataTreeReadWriteTransaction txFromChain = txChain.newReadWriteTransaction();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    boolean printReturnValue = tracingBroker.printOpenTransactions(ps, 1);
    String output = new String(baos.toByteArray(), UTF_8);
    assertThat(printReturnValue).isTrue();
    // Assert expectations about stack trace
    assertThat(output).contains("testPrintOpenTransactions(TracingBrokerTest.java");
    assertThat(output).doesNotContain(TracingBroker.class.getName());
    String previousLine = "";
    for (String line : output.split("\n")) {
        if (line.contains("(...")) {
            assertThat(previousLine.contains("(...)")).isFalse();
        }
        previousLine = line;
    }
    // assert that the sorting works - the x3 is shown before the x1
    assertThat(output).contains("  DataBroker : newReadWriteTransaction()\n    3x");
// We don't do any verify/times on the mocks,
// because the main point of the test is just to verify that
// printOpenTransactions runs through without any exceptions
// (e.g. it used to have a ClassCastException).
}
Also used : DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) PrintStream(java.io.PrintStream) Config(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsaltrace.rev160908.Config) ConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsaltrace.rev160908.ConfigBuilder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TracingBroker(org.opendaylight.mdsal.trace.impl.TracingBroker) DOMTransactionChain(org.opendaylight.mdsal.dom.api.DOMTransactionChain) DOMDataBroker(org.opendaylight.mdsal.dom.api.DOMDataBroker) BindingCodecTree(org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree) Test(org.junit.Test)

Example 8 with Config

use of com.icodici.universa.node2.Config in project kubernetes-client by fabric8io.

the class ConfigTest method get.

@Test
void get() {
    // Given
    server.expect().get().withPath("/apis/operator.openshift.io/v1/configs/test-get").andReturn(HttpURLConnection.HTTP_OK, createNewConfig("test-get")).once();
    // When
    Config config = client.operator().configs().withName("test-get").get();
    // Then
    assertThat(config).isNotNull().hasFieldOrPropertyWithValue("metadata.name", "test-get");
}
Also used : Config(io.fabric8.openshift.api.model.operator.v1.Config) Test(org.junit.jupiter.api.Test)

Example 9 with Config

use of com.icodici.universa.node2.Config in project nc-reactor-generator by ThizThizzyDizzy.

the class NCPFExporter method saveConfig.

private static void saveConfig(FileOutputStream stream) {
    Config config = Config.newConfig();
    config.set("partial", true);
    Config overhaulCfg = Config.newConfig();
    Config fissionSFR = Config.newConfig();
    ConfigList blocks = new ConfigList();
    for (ReactorPart part : ReactorPart.parts) {
        Config block = Config.newConfig();
        block.set("name", part.toString());
        // everything but conductors
        block.set("functional", true);
        switch(part.type) {
            case AIR:
            case CASING:
                continue;
            case CONDUCTOR:
                block.set("functional", false);
                block.set("cluster", true);
                break;
            case FUEL_CELL:
                // that's a source!
                if (((FuelCell) part).efficiency != 0)
                    continue;
                block.set("fuelCell", true);
                block.set("cluster", true);
                block.set("createCluster", true);
                block.set("blocksLOS", true);
                break;
            case HEATSINK:
                Heatsink sink = (Heatsink) part;
                block.set("cluster", true);
                block.set("cooling", sink.cooling);
                ConfigList rules = new ConfigList();
                for (PlacementRule rule : sink.rules) {
                    Config rul = Config.newConfig();
                    switch(rule.type) {
                        case AXIS:
                            rul.set("min", (byte) 1);
                            rul.set("max", (byte) 3);
                            if (rule.bit instanceof ReactorPart) {
                                rul.set("type", (byte) 1);
                                rul.set("block", (byte) (byte) (rule.bit == ReactorPart.AIR ? 0 : ReactorPart.parts.indexOf(rule.bit) + 1));
                            } else {
                                rul.set("type", (byte) 3);
                                switch((ReactorPart.Type) rule.bit) {
                                    case AIR:
                                        rul.set("block", (byte) 0);
                                        break;
                                    case CASING:
                                        rul.set("block", (byte) 1);
                                        break;
                                    case HEATSINK:
                                        rul.set("block", (byte) 2);
                                        break;
                                    case FUEL_CELL:
                                        rul.set("block", (byte) 3);
                                        break;
                                    case MODERATOR:
                                        if (part instanceof NeutronShield) {
                                            rul.set("block", (byte) 6);
                                        } else
                                            rul.set("block", (byte) 4);
                                        break;
                                    case REFLECTOR:
                                        rul.set("block", (byte) 5);
                                        break;
                                    case IRRADIATOR:
                                        rul.set("block", (byte) 7);
                                        break;
                                    case CONDUCTOR:
                                        rul.set("block", (byte) 8);
                                        break;
                                }
                            }
                        case BETWEEN:
                            rul.set("min", (byte) rule.min);
                            rul.set("max", (byte) Math.min(6, rule.max));
                            if (rule.bit instanceof ReactorPart) {
                                rul.set("type", (byte) 0);
                                rul.set("block", (byte) (rule.bit == ReactorPart.AIR ? 0 : ReactorPart.parts.indexOf(rule.bit) + 1));
                            } else {
                                rul.set("type", (byte) 2);
                                switch((ReactorPart.Type) rule.bit) {
                                    case AIR:
                                        rul.set("block", (byte) 0);
                                        break;
                                    case CASING:
                                        rul.set("block", (byte) 1);
                                        break;
                                    case HEATSINK:
                                        rul.set("block", (byte) 2);
                                        break;
                                    case FUEL_CELL:
                                        rul.set("block", (byte) 3);
                                        break;
                                    case MODERATOR:
                                        if (part instanceof NeutronShield) {
                                            rul.set("block", (byte) 6);
                                        } else
                                            rul.set("block", (byte) 4);
                                        break;
                                    case REFLECTOR:
                                        rul.set("block", (byte) 5);
                                        break;
                                    case IRRADIATOR:
                                        rul.set("block", (byte) 7);
                                        break;
                                    case CONDUCTOR:
                                        rul.set("block", (byte) 8);
                                        break;
                                }
                            }
                            break;
                    }
                    rules.add(rul);
                }
                block.set("rules", rules);
                break;
            case IRRADIATOR:
                block.set("irradiator", true);
                block.set("cluster", true);
                block.set("createCluster", true);
                break;
            case MODERATOR:
                block.set("moderator", true);
                block.set("flux", ((Moderator) part).fluxFactor);
                block.set("efficiency", (float) ((Moderator) part).efficiencyFactor);
                if (part instanceof NeutronShield) {
                    block.set("shield", true);
                    block.set("heatMult", ((NeutronShield) part).heatMult);
                    block.set("cluster", true);
                    block.set("createCluster", true);
                } else {
                    block.set("activeModerator", true);
                }
                break;
            case REFLECTOR:
                block.set("blocksLOS", true);
                block.set("reflector", true);
                block.set("efficiency", ((Reflector) part).efficiency);
                block.set("reflectivity", ((Reflector) part).reflectivity);
                block.set("blocksLOS", true);
                break;
        }
        blocks.add(block);
    }
    fissionSFR.set("blocks", blocks);
    ConfigList fuels = new ConfigList();
    for (Fuel f : Fuel.fuels) {
        for (Fuel.Type typ : Fuel.Type.values()) {
            Config fuel = Config.newConfig();
            fuel.set("name", "[" + typ.name() + "]" + f.toString());
            fuel.set("efficiency", f.efficiency.get(typ).floatValue());
            fuel.set("heat", f.heat.get(typ).floatValue());
            fuel.set("criticality", f.criticality.get(typ).intValue());
            fuel.set("selfPriming", f.selfPriming.get(typ).intValue() == 1);
            fuel.set("time", 0);
            fuels.add(fuel);
        }
    }
    fissionSFR.set("fuels", fuels);
    ConfigList sources = new ConfigList();
    for (ReactorPart part : ReactorPart.GROUP_CELLS) {
        if (((FuelCell) part).efficiency == 0)
            continue;
        Config source = Config.newConfig();
        String nam = part.toString();
        source.set("name", nam.substring(11, nam.length() - 1));
        source.set("efficiency", ((FuelCell) part).efficiency);
        sources.add(source);
    }
    fissionSFR.set("sources", sources);
    ConfigList irradiatorRecipes = new ConfigList();
    fissionSFR.set("irradiatorRecipes", irradiatorRecipes);
    overhaulCfg.set("fissionSFR", fissionSFR);
    config.set("overhaul", overhaulCfg);
    config.save(stream);
}
Also used : Config(simplelibrary.config2.Config) ConfigList(simplelibrary.config2.ConfigList)

Example 10 with Config

use of com.icodici.universa.node2.Config in project nc-reactor-generator by ThizThizzyDizzy.

the class NCPFExporter method saveHeader.

private static void saveHeader(FileOutputStream stream) {
    Config header = Config.newConfig();
    header.set("version", (byte) 1);
    header.set("count", 1);
    header.save(stream);
}
Also used : Config(simplelibrary.config2.Config)

Aggregations

Config (sun.security.krb5.Config)8 Test (org.junit.Test)7 IOException (java.io.IOException)6 Config (simplelibrary.config2.Config)6 KeyAddress (com.icodici.crypto.KeyAddress)5 File (java.io.File)5 TimeoutException (java.util.concurrent.TimeoutException)4 Before (org.junit.Before)3 Timeout (akka.util.Timeout)2 PrivateKey (com.icodici.crypto.PrivateKey)2 com.icodici.universa.contract (com.icodici.universa.contract)2 QuorumVoteRole (com.icodici.universa.contract.roles.QuorumVoteRole)2 com.icodici.universa.contract.services (com.icodici.universa.contract.services)2 Config (com.icodici.universa.node2.Config)2 EventExecutor (io.netty.util.concurrent.EventExecutor)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ZonedDateTime (java.time.ZonedDateTime)2 java.util (java.util)2 HashSet (java.util.HashSet)2 java.util.concurrent (java.util.concurrent)2