Search in sources :

Example 1 with Config

use of simplelibrary.config2.Config in project universa by UniversaBlockchain.

the class PostgresLedgerTest method paymentSaveTest.

@Test
public void paymentSaveTest() throws Exception {
    try (PooledDb db = (PooledDb) ledger.getDb()) {
        try (PreparedStatement statement = db.statement("delete from payments_summary;")) {
            statement.executeUpdate();
        }
    }
    NodeStats stats = new NodeStats();
    Config config = new Config();
    stats.init(ledger, config);
    ZonedDateTime now = ZonedDateTime.now();
    ZonedDateTime dateTime = now.minusDays(now.getDayOfMonth() - 1).minusMonths(1);
    while (dateTime.isBefore(ZonedDateTime.now().plusSeconds(1))) {
        ledger.savePayment(100, dateTime);
        ledger.savePayment(100, dateTime);
        dateTime = dateTime.plusDays(1);
    }
    stats.collect(ledger, config);
// assertEquals(stats.todayPaidAmount,200);
// assertEquals(stats.yesterdayPaidAmount,200);
// assertEquals(stats.thisMonthPaidAmount,200*now.getDayOfMonth());
// assertEquals(stats.lastMonthPaidAmount,200*now.minusMonths(1).getMonth().length(now.getYear() % 4 == 0));
}
Also used : NodeStats(com.icodici.universa.node2.NodeStats) PooledDb(com.icodici.db.PooledDb) ZonedDateTime(java.time.ZonedDateTime) Config(com.icodici.universa.node2.Config) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test)

Example 2 with Config

use of simplelibrary.config2.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 3 with Config

use of simplelibrary.config2.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 4 with Config

use of simplelibrary.config2.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 5 with Config

use of simplelibrary.config2.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)6 Config (simplelibrary.config2.Config)6 Config (com.icodici.universa.node2.Config)3 TimeoutException (java.util.concurrent.TimeoutException)3 Timeout (akka.util.Timeout)2 KeyAddress (com.icodici.crypto.KeyAddress)2 EventExecutor (io.netty.util.concurrent.EventExecutor)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Before (org.junit.Before)2 BeforeClass (org.junit.BeforeClass)2 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)2 JULogging (org.neo4j.driver.internal.logging.JULogging)2 Config (org.neo4j.driver.v1.Config)2 Driver (org.neo4j.driver.v1.Driver)2 Session (org.neo4j.driver.v1.Session)2 ClientException (org.neo4j.driver.v1.exceptions.ClientException)2 ServiceUnavailableException (org.neo4j.driver.v1.exceptions.ServiceUnavailableException)2 SessionExpiredException (org.neo4j.driver.v1.exceptions.SessionExpiredException)2