Search in sources :

Example 16 with Config

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

the class BoltCausalClusteringIT method shouldPickANewServerToWriteToOnLeaderSwitch.

@Test
public void shouldPickANewServerToWriteToOnLeaderSwitch() throws Throwable {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
    CoreClusterMember leader = cluster.awaitLeader();
    LeaderSwitcher leaderSwitcher = new LeaderSwitcher(cluster);
    Config config = Config.build().withLogging(new JULogging(Level.OFF)).toConfig();
    Set<BoltServerAddress> seenAddresses = new HashSet<>();
    try (Driver driver = GraphDatabase.driver(leader.routingURI(), AuthTokens.basic("neo4j", "neo4j"), config)) {
        boolean success = false;
        long deadline = System.currentTimeMillis() + (30 * 1000);
        while (!success) {
            if (System.currentTimeMillis() > deadline) {
                fail("Failed to write to the new leader in time. Addresses seen: " + seenAddresses);
            }
            try (Session session = driver.session(AccessMode.WRITE)) {
                BoltServerAddress boltServerAddress = ((RoutingNetworkSession) session).address();
                session.run("CREATE (p:Person)");
                seenAddresses.add(boltServerAddress);
                success = seenAddresses.size() >= 2;
            } catch (Exception e) {
                Thread.sleep(100);
            }
            /*
                 * Having the latch release here ensures that we've done at least one pass through the loop, which means
                 * we've completed a connection before the forced master switch.
                 */
            if (seenAddresses.size() >= 1) {
                leaderSwitcher.start();
            }
        }
    } finally {
        leaderSwitcher.stop();
        assertTrue(leaderSwitcher.hadLeaderSwitch());
        assertThat(seenAddresses.size(), greaterThanOrEqualTo(2));
    }
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Config(org.neo4j.driver.v1.Config) Driver(org.neo4j.driver.v1.Driver) TimeoutException(java.util.concurrent.TimeoutException) SessionExpiredException(org.neo4j.driver.v1.exceptions.SessionExpiredException) ServiceUnavailableException(org.neo4j.driver.v1.exceptions.ServiceUnavailableException) IOException(java.io.IOException) ClientException(org.neo4j.driver.v1.exceptions.ClientException) BoltServerAddress(org.neo4j.driver.internal.net.BoltServerAddress) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) JULogging(org.neo4j.driver.internal.logging.JULogging) HashSet(java.util.HashSet) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

Example 17 with Config

use of com.icodici.universa.node2.Config in project jdk8u_jdk by JetBrains.

the class EType method initStatic.

public static void initStatic() {
    boolean allowed = false;
    try {
        Config cfg = Config.getInstance();
        String temp = cfg.get("libdefaults", "allow_weak_crypto");
        if (temp != null && temp.equals("true"))
            allowed = true;
    } catch (Exception exc) {
        if (DEBUG) {
            System.out.println("Exception in getting allow_weak_crypto, " + "using default value " + exc.getMessage());
        }
    }
    allowWeakCrypto = allowed;
}
Also used : Config(sun.security.krb5.Config) KrbCryptoException(sun.security.krb5.KrbCryptoException) KrbException(sun.security.krb5.KrbException)

Example 18 with Config

use of com.icodici.universa.node2.Config in project jdk8u_jdk by JetBrains.

the class ParseConfig method main.

public static void main(String[] args) throws Exception {
    System.setProperty("java.security.krb5.conf", System.getProperty("test.src", ".") + "/krb5.conf");
    Config config = Config.getInstance();
    config.listTable();
    String sample = "kdc.example.com kdc2.example.com";
    for (int i = 0; i < 4; i++) {
        String expected = config.getAll("realms", "EXAMPLE_" + i + ".COM", "kdc");
        if (!sample.equals(expected)) {
            throw new Exception("krb5.conf: unexpected kdc value \"" + expected + "\"");
        }
    }
    // JDK-8055045: IOOBE when reading an empty value
    config.get("empty1", "NOVAL.COM");
    config.get("empty2", "NOVAL.COM");
    config.get("quote1", "NOVAL.COM");
    config.get("quote2", "NOVAL.COM");
}
Also used : Config(sun.security.krb5.Config)

Example 19 with Config

use of com.icodici.universa.node2.Config in project jdk8u_jdk by JetBrains.

the class DNS method main.

public static void main(String[] args) throws Exception {
    System.setProperty("java.security.krb5.conf", System.getProperty("test.src", ".") + "/no-such-file.conf");
    Config config = Config.getInstance();
    try {
        String r = config.getDefaultRealm();
        throw new Exception("What? There is a default realm " + r + "?");
    } catch (KrbException ke) {
        ke.printStackTrace();
        if (ke.getCause() != null) {
            throw new Exception("There should be no cause. Won't try DNS");
        }
    }
    String kdcs = config.getKDCList("X");
    if (!kdcs.equals("a.com.:88 b.com.:99") && !kdcs.equals("a.com. b.com.:99")) {
        throw new Exception("Strange KDC: [" + kdcs + "]");
    }
    ;
}
Also used : Config(sun.security.krb5.Config) KrbException(sun.security.krb5.KrbException) KrbException(sun.security.krb5.KrbException)

Example 20 with Config

use of com.icodici.universa.node2.Config in project jdk8u_jdk by JetBrains.

the class SCDynamicConfigTest method main.

public static void main(String[] args) throws Exception {
    // Reconstruct a typical SCDynamicConfig.getKerberosConfig() output
    Hashtable<String, Object> conf = new Hashtable<>();
    Hashtable<String, Object> libdefaults = new Hashtable<>();
    libdefaults.put("default_realm", "REALM.COM");
    conf.put("libdefaults", libdefaults);
    Hashtable<String, Object> realms = new Hashtable<>();
    Hashtable<String, Object> thisRealm = new Hashtable<>();
    realms.put("REALM.COM", thisRealm);
    thisRealm.put("kpasswd", hosts());
    thisRealm.put("kadmin", hosts());
    thisRealm.put("kdc", hosts());
    conf.put("realms", realms);
    Hashtable<String, Object> domain_realm = new Hashtable<>();
    domain_realm.put(".realm.com", "REALM.COM");
    domain_realm.put("realm.com", "REALM.COM");
    conf.put("domain_realm", domain_realm);
    System.out.println("SCDynamicConfig:\n");
    System.out.println(conf);
    // Simulate SCDynamicConfig.getConfig() output
    Method m = SCDynamicStoreConfig.class.getDeclaredMethod("convertNativeConfig", Hashtable.class);
    m.setAccessible(true);
    conf = (Hashtable) m.invoke(null, conf);
    System.out.println("\nkrb5.conf:\n");
    System.out.println(conf);
    // Feed it into a Config object
    System.setProperty("java.security.krb5.conf", "not-a-file");
    Config cf = Config.getInstance();
    Field f = Config.class.getDeclaredField("stanzaTable");
    f.setAccessible(true);
    f.set(cf, conf);
    System.out.println("\nConfig:\n");
    System.out.println(cf);
    if (!cf.getDefaultRealm().equals("REALM.COM")) {
        throw new Exception();
    }
    if (!cf.getKDCList("REALM.COM").equals("127.0.0.1 127.0.0.2")) {
        throw new Exception();
    }
    if (!cf.get("domain_realm", ".realm.com").equals("REALM.COM")) {
        throw new Exception();
    }
}
Also used : Field(java.lang.reflect.Field) Hashtable(java.util.Hashtable) SCDynamicStoreConfig(sun.security.krb5.SCDynamicStoreConfig) Config(sun.security.krb5.Config) Method(java.lang.reflect.Method)

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