org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi Java Examples

The following examples show how to use org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GridifySingleSplitLoadTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration() throws Exception {
    IgniteConfiguration cfg = super.getConfiguration();

    /* Uncomment following code if you start it manually. */
        CommunicationSpi commSpi = new TcpCommunicationSpi();

        cfg.setCommunicationSpi(commSpi);

        DiscoverySpi discoSpi = new TcpDiscoverySpi();

        cfg.setDiscoverySpi(discoSpi);
    /*
     */
    @SuppressWarnings("TypeMayBeWeakened")
    Log4JLogger log = (Log4JLogger)cfg.getGridLogger();

    log.getLogger("org.apache.ignite").setLevel(Level.INFO);

    return cfg;
}
 
Example #2
Source File: IgniteInterpreterTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
  TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
  ipFinder.setAddresses(Collections.singletonList(HOST));

  TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
  discoSpi.setIpFinder(ipFinder);

  IgniteConfiguration cfg = new IgniteConfiguration();
  cfg.setDiscoverySpi(discoSpi);

  cfg.setGridName("test");

  ignite = Ignition.start(cfg);

  Properties props = new Properties();
  props.setProperty(IgniteSqlInterpreter.IGNITE_JDBC_URL,
          "jdbc:ignite:cfg://[email protected]");
  props.setProperty(IgniteInterpreter.IGNITE_CLIENT_MODE, "false");
  props.setProperty(IgniteInterpreter.IGNITE_PEER_CLASS_LOADING_ENABLED, "false");
  props.setProperty(IgniteInterpreter.IGNITE_ADDRESSES, HOST);

  intp = new IgniteInterpreter(props);
  intp.open();
}
 
Example #3
Source File: GridAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Optimizes configuration to achieve better test performance.
 *
 * @param cfg Configuration.
 * @return Optimized configuration (by modifying passed in one).
 * @throws IgniteCheckedException On error.
 */
protected IgniteConfiguration optimize(IgniteConfiguration cfg) throws IgniteCheckedException {
    if (cfg.getLocalHost() == null) {
        if (cfg.getDiscoverySpi() instanceof TcpDiscoverySpi) {
            cfg.setLocalHost("127.0.0.1");

            if (((TcpDiscoverySpi)cfg.getDiscoverySpi()).getJoinTimeout() == 0)
                ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setJoinTimeout(10000);
        }
        else
            cfg.setLocalHost(getTestResources().getLocalHost());
    }

    // Do not add redundant data if it is not needed.
    if (cfg.getIncludeProperties() == null)
        cfg.setIncludeProperties();

    return cfg;
}
 
Example #4
Source File: IgniteDiscoveryMassiveNodeFailTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Check that cluster recovers from temporal connection breakage.
 *
 * @throws Exception If failed.
 */
@Test
public void testRecoveryOnDisconnect() throws Exception {
    startGrids(3);

    IgniteEx ignite1 = grid(1);
    IgniteEx ignite2 = grid(2);

    ((TcpDiscoverySpi)ignite1.configuration().getDiscoverySpi()).brakeConnection();
    ((TcpDiscoverySpi)ignite2.configuration().getDiscoverySpi()).brakeConnection();

    doSleep(FAILURE_DETECTION_TIMEOUT);

    assertEquals(3, grid(0).cluster().nodes().size());
    assertEquals(3, grid(1).cluster().nodes().size());
    assertEquals(3, grid(2).cluster().nodes().size());
}
 
Example #5
Source File: TxPessimisticDeadlockDetectionTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    if (isDebug()) {
        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();

        discoSpi.failureDetectionTimeoutEnabled(false);

        cfg.setDiscoverySpi(discoSpi);
    }

    DataStorageConfiguration memCfg = new DataStorageConfiguration().setDefaultDataRegionConfiguration(
        new DataRegionConfiguration()
            .setMaxSize(DataStorageConfiguration.DFLT_DATA_REGION_MAX_SIZE * 10)
            .setName("dfltPlc"));

    cfg.setDataStorageConfiguration(memCfg);

    return cfg;
}
 
Example #6
Source File: HibernateL2CacheConfigurationSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();

    discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    cfg.setDiscoverySpi(discoSpi);

    cfg.setCacheConfiguration(cacheConfiguration(ENTITY3_NAME),
        cacheConfiguration(ENTITY4_NAME),
        cacheConfiguration("cache1"),
        cacheConfiguration("cache2"),
        cacheConfiguration("cache3"),
        cacheConfiguration(DEFAULT_UPDATE_TIMESTAMPS_REGION_UNQUALIFIED_NAME),
        cacheConfiguration(DEFAULT_QUERY_RESULTS_REGION_UNQUALIFIED_NAME));

    return cfg;
}
 
Example #7
Source File: LocalIgniteCluster.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** Private constructor: use {@link #start(int)} to create instances of {@link LocalIgniteCluster}. */
private LocalIgniteCluster(int initSize) {
    if (initSize < 1)
        throw new IllegalArgumentException("Cluster must have at least one node.");

    this.initSize = initSize;

    for (int i = 0; i < initSize; i++) {
        IgniteConfiguration cfg = getConfiguration(
            new NodeConfiguration(TcpDiscoverySpi.DFLT_PORT + i, ClientConnectorConfiguration.DFLT_PORT + i)
        );

        Ignite ignite = Ignition.start(cfg);

        srvs.add(ignite);
    }
}
 
Example #8
Source File: GridReleaseTypeSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi() {
        @Override public void setNodeAttributes(Map<String, Object> attrs,
            IgniteProductVersion ver) {
            super.setNodeAttributes(attrs, ver);

            attrs.put(IgniteNodeAttributes.ATTR_BUILD_VER, nodeVer);
        }
    };

    discoSpi.setIpFinder(sharedStaticIpFinder).setForceServerMode(true);

    cfg.setDiscoverySpi(discoSpi);

    return cfg;
}
 
Example #9
Source File: LruNearOnlyNearEvictionPolicySelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);

    if (getTestIgniteInstanceIndex(igniteInstanceName) != 0) {
        CacheConfiguration cc = new CacheConfiguration(DEFAULT_CACHE_NAME);

        cc.setCacheMode(cacheMode);
        cc.setAtomicityMode(atomicityMode);
        cc.setWriteSynchronizationMode(PRIMARY_SYNC);
        cc.setRebalanceMode(SYNC);
        cc.setBackups(0);

        c.setCacheConfiguration(cc);
    }

    ((TcpDiscoverySpi)c.getDiscoverySpi()).setForceServerMode(true);

    return c;
}
 
Example #10
Source File: CheckpointFreeListTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    cfg.setConsistentId(igniteInstanceName);

    DataStorageConfiguration storageCfg = new DataStorageConfiguration();

    storageCfg.setCheckpointThreads(2);
    storageCfg.getDefaultDataRegionConfiguration()
        .setPersistenceEnabled(true)
        .setMaxSize(300L * 1024 * 1024);

    cfg.setDataStorageConfiguration(storageCfg)
        .setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER))
        .setCacheConfiguration(cacheConfiguration(CACHE_NAME, CacheAtomicityMode.TRANSACTIONAL));

    return cfg;
}
 
Example #11
Source File: ClientConnectorConfigurationValidationSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Get base node configuration.
 *
 * @return Configuration.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private IgniteConfiguration baseConfiguration() throws Exception {
    final IgniteConfiguration cfg = super.getConfiguration();

    cfg.setIgniteInstanceName(ClientConnectorConfigurationValidationSelfTest.class.getName() + "-" +
        NODE_IDX_GEN.incrementAndGet());

    cfg.setLocalHost("127.0.0.1");
    cfg.setMarshaller(new BinaryMarshaller());

    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    spi.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    cfg.setDiscoverySpi(spi);

    CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME)
        .setIndexedTypes(ClientConnectorKey.class, ClientConnectorValue.class);

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
Example #12
Source File: HibernateL2CacheSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();

    discoSpi.setIpFinder(IP_FINDER);

    cfg.setDiscoverySpi(discoSpi);

    cfg.setCacheConfiguration(generalRegionConfiguration(DEFAULT_UPDATE_TIMESTAMPS_REGION_UNQUALIFIED_NAME),
        generalRegionConfiguration(DEFAULT_QUERY_RESULTS_REGION_UNQUALIFIED_NAME),
        transactionalRegionConfiguration(ENTITY_NAME),
        transactionalRegionConfiguration(ENTITY2_NAME),
        transactionalRegionConfiguration(VERSIONED_ENTITY_NAME),
        transactionalRegionConfiguration(PARENT_ENTITY_NAME),
        transactionalRegionConfiguration(CHILD_ENTITY_NAME),
        transactionalRegionConfiguration(CHILD_COLLECTION_REGION),
        transactionalRegionConfiguration(NATURAL_ID_REGION),
        transactionalRegionConfiguration(NATURAL_ID_REGION2));

    return cfg;
}
 
Example #13
Source File: PartitionsExchangeAwareTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER));

    cfg.setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(
        new DataRegionConfiguration().setMaxSize(100 * 1024 * 1024)));

    CacheConfiguration atomicCfg = new CacheConfiguration()
        .setName(ATOMIC_CACHE_NAME)
        .setAffinity(new RendezvousAffinityFunction(false, 16));

    CacheConfiguration txCfg = new CacheConfiguration()
        .setName(TX_CACHE_NAME)
        .setAffinity(new RendezvousAffinityFunction(false, 16));

    cfg.setCacheConfiguration(atomicCfg, txCfg);

    return cfg;
}
 
Example #14
Source File: GridFactorySelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testRepeatingStart() throws Exception {
    try {
        IgniteConfiguration c = getConfiguration("1");

        startGrid("1", c);

        if (tcpDiscovery())
            assert ((TcpDiscoverySpi)c.getDiscoverySpi()).started();

        try {
            startGrid("2", c);

            fail("Should not be able to start grid using same configuration instance.");
        }
        catch (Exception e) {
            info("Caught expected exception: " + e);
        }
    }
    finally {
        stopAllGrids();
    }
}
 
Example #15
Source File: GridCacheTcpClientDiscoveryMultiThreadedTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    // Filling configuration for client nodes
    if (client) {
        TcpDiscoveryVmIpFinder clientFinder = new TcpDiscoveryVmIpFinder();
        Collection<String> addrs = new ArrayList<>(ipFinder.getRegisteredAddresses().size());

        for (InetSocketAddress sockAddr : ipFinder.getRegisteredAddresses())
            addrs.add(sockAddr.getHostString() + ":" + sockAddr.getPort());

        clientFinder.setAddresses(addrs);

        cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(clientFinder));
    }

    cfg.setLocalHost("127.0.0.1");

    return cfg;
}
 
Example #16
Source File: JdbcThinStatementCancelSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration<?,?> cache = defaultCacheConfiguration();

    cache.setCacheMode(PARTITIONED);
    cache.setBackups(1);
    cache.setWriteSynchronizationMode(FULL_SYNC);
    cache.setSqlFunctionClasses(TestSQLFunctions.class);
    cache.setIndexedTypes(Integer.class, Integer.class, Long.class, Long.class, String.class,
        JdbcThinAbstractDmlStatementSelfTest.Person.class);

    cfg.setCacheConfiguration(cache);

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(IP_FINDER);

    cfg.setDiscoverySpi(disco);

    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration().
        setThreadPoolSize(SERVER_THREAD_POOL_SIZE));

    return cfg;
}
 
Example #17
Source File: GridAddressResolverSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(final String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
    discoSpi.setIpFinder(IP_FINDER);
    cfg.setDiscoverySpi(discoSpi);

    cfg.setAddressResolver(new AddressResolver() {
        @Override public Collection<InetSocketAddress> getExternalAddresses(
            InetSocketAddress addr) throws IgniteCheckedException {
            Set<InetSocketAddress> set = new HashSet<>();

            set.add(addr);
            set.add(igniteInstanceName.contains("0") ? addr0 : addr1);

            return set;
        }
    });

    return cfg;
}
 
Example #18
Source File: GridAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @return Test kernal context.
 */
protected GridTestKernalContext newContext() throws IgniteCheckedException {
    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setClientMode(false);
    cfg.setDiscoverySpi(new TcpDiscoverySpi() {
        @Override public void sendCustomEvent(DiscoverySpiCustomMessage msg) throws IgniteException {
            // No-op.
        }
    });
    cfg.setSystemViewExporterSpi(new JmxSystemViewExporterSpi() {
        @Override protected void register(SystemView<?> sysView) {
            // No-op.
        }
    });

    GridTestKernalContext ctx = new GridTestKernalContext(log(), cfg);
    return ctx;
}
 
Example #19
Source File: IgniteCacheAbstractQuerySelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);

    ((TcpDiscoverySpi)c.getDiscoverySpi()).setForceServerMode(true);

    if (igniteInstanceName.startsWith("client"))
        c.setDataStorageConfiguration(new DataStorageConfiguration());

    c.setIncludeEventTypes(EventType.EVTS_ALL);

    return c;
}
 
Example #20
Source File: TxPartitionCounterStateAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    cfg.setActiveOnStart(false);
    cfg.setAutoActivationEnabled(false);

    cfg.setConsistentId("node" + igniteInstanceName);
    cfg.setFailureHandler(new StopNodeFailureHandler());
    cfg.setRebalanceThreadPoolSize(4); // Necessary to reproduce some issues.

    ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);

    // TODO set this only for historical rebalance tests.
    cfg.setCommunicationSpi(new IgniteWalRebalanceTest.WalRebalanceCheckingCommunicationSpi());

    cfg.setDataStorageConfiguration(new DataStorageConfiguration().
        setWalHistorySize(1000).
        setWalSegmentSize(8 * MB).setWalMode(LOG_ONLY).setPageSize(1024).
        setCheckpointFrequency(MILLISECONDS.convert(365, DAYS)).
        setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(persistenceEnabled()).
            setInitialSize(100 * MB).setMaxSize(100 * MB)));

    if (!igniteInstanceName.startsWith(CLIENT_GRID_NAME))
        cfg.setCacheConfiguration(cacheConfiguration(DEFAULT_CACHE_NAME));

    return cfg;
}
 
Example #21
Source File: DynamicIndexAbstractConcurrentSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration commonConfiguration(int idx) throws Exception {
    IgniteConfiguration cfg = super.commonConfiguration(idx);

    TestTcpDiscoverySpi testSpi = new TestTcpDiscoverySpi();

    if (cfg.getDiscoverySpi() instanceof TcpDiscoverySpi &&
        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).getIpFinder() != null)
        testSpi.setIpFinder(((TcpDiscoverySpi)cfg.getDiscoverySpi()).getIpFinder());

    return cfg.setDiscoverySpi(testSpi);
}
 
Example #22
Source File: HibernateL2CacheStrategySelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(new TcpDiscoveryVmIpFinder(true));

    cfg.setCacheConfiguration(cacheConfiguration(ENTITY3_NAME),
        cacheConfiguration(ENTITY4_NAME),
        cacheConfiguration("cache1"),
        cacheConfiguration("cache2"),
        cacheConfiguration(DEFAULT_UPDATE_TIMESTAMPS_REGION_UNQUALIFIED_NAME),
        cacheConfiguration(DEFAULT_QUERY_RESULTS_REGION_UNQUALIFIED_NAME));

    return cfg;
}
 
Example #23
Source File: ParameterTypeInferenceTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String name) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(name);

    cfg.setLocalHost("127.0.0.1");
    cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER));

    return cfg;
}
 
Example #24
Source File: InvalidServerTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String instanceName,
        AbstractTestSecurityPluginProvider pluginProv) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(instanceName, pluginProv);

    cfg.setDiscoverySpi(new TcpDiscoverySpi() {
        @Override protected void startMessageProcess(TcpDiscoveryAbstractMessage msg) {
            if (msg instanceof TcpDiscoveryNodeAddedMessage && msg.verified())
                TestSecurityProcessor.PERMS.remove(new SecurityCredentials(TEST_SERVER_NAME, ""));
        }
    }.setIpFinder(LOCAL_IP_FINDER));

    return cfg;
}
 
Example #25
Source File: CacheInterceptorPartitionCounterLocalSanityTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(new TcpDiscoveryVmIpFinder(true));

    return cfg;
}
 
Example #26
Source File: GridCacheRendezvousAffinityClientSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setForceServerMode(true);

    CacheConfiguration ccfg = defaultCacheConfiguration();

    ccfg.setCacheMode(CacheMode.PARTITIONED);
    ccfg.setBackups(1);
    ccfg.setAffinity(new RendezvousAffinityFunction());
    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
Example #27
Source File: IgniteNodeRunner.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Reads configuration from given file and delete the file after.
 *
 * @param fileName File name.
 * @return Readed configuration.
 * @throws IOException If failed.
 * @see #storeToFile(IgniteConfiguration, boolean)
 * @throws IgniteCheckedException On error.
 */
private static IgniteConfiguration readCfgFromFileAndDeleteFile(String fileName)
    throws IOException, IgniteCheckedException {
    try (BufferedReader cfgReader = new BufferedReader(new FileReader(fileName))) {
        IgniteConfiguration cfg = (IgniteConfiguration)new XStream().fromXML(cfgReader);

        if (cfg.getMarshaller() == null) {
            Marshaller marsh = IgniteTestResources.getMarshaller();

            cfg.setMarshaller(marsh);
        }

        X.println("Configured marshaller class: " + cfg.getMarshaller().getClass().getName());

        if (cfg.getDiscoverySpi() == null) {
            TcpDiscoverySpi disco = new TcpDiscoverySpi();
            disco.setIpFinder(GridCacheAbstractFullApiSelfTest.LOCAL_IP_FINDER);
            cfg.setDiscoverySpi(disco);
        }

        X.println("Configured discovery: " + cfg.getDiscoverySpi().getClass().getName());

        return cfg;
    }
    finally {
        new File(fileName).delete();
    }
}
 
Example #28
Source File: GridSpiLocalHostInjectionTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Performs test of {@code localHost} resource injection for {@link org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi}.
 *
 * @param cfgVal {@code true} if {@code localHost} should be set in configuration adapter.
 * @param spiVal {@code true} if {@code localHost} should be set in SPI
 * @param exp Expected value of {@code localHost} property in SPI after injection.
 * @throws IgniteCheckedException If test fails.
 */
private void processTcpDiscoverySpiTestInjection(boolean cfgVal, boolean spiVal, @Nullable String exp)
    throws IgniteCheckedException {
    GridResourceProcessor proc = getResourceProcessor(cfgVal);

    TcpDiscoverySpi spi = new TcpDiscoverySpi();

    if (spiVal)
        spi.setLocalAddress(SPI_LOCAL_ADDR_VALUE);

    proc.inject(spi);

    assertEquals("Invalid localAddr value after injection: ", exp, spi.getLocalAddress());
}
 
Example #29
Source File: MetaStorageCompatibilityTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the given ignite configuration.
 *
 * @param cfg Ignite configuration to be updated.
 * @param consistentId Consistent id.
 * @param failOnFileRmv Indicates that an exception should be trown when partition/index file is going to be removed.
 * @return Updated configuration.
 */
private static IgniteConfiguration prepareConfig(
    IgniteConfiguration cfg,
    @Nullable String consistentId,
    @Nullable String failOnFileRmv
) {
    cfg.setLocalHost("127.0.0.1");

    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(GridCacheAbstractFullApiSelfTest.LOCAL_IP_FINDER);

    cfg.setDiscoverySpi(disco);

    cfg.setPeerClassLoadingEnabled(false);

    DataStorageConfiguration memCfg = new DataStorageConfiguration()
        .setDefaultDataRegionConfiguration(
            new DataRegionConfiguration()
                .setPersistenceEnabled(true)
                .setInitialSize(10L * 1024 * 1024)
                .setMaxSize(10L * 1024 * 1024))
        .setPageSize(4096);

    cfg.setDataStorageConfiguration(memCfg);

    if (consistentId != null) {
        cfg.setIgniteInstanceName(consistentId);
        cfg.setConsistentId(consistentId);
    }

    if (failOnFileRmv != null)
        cfg.getDataStorageConfiguration().setFileIOFactory(new FailingFileIOFactory(failOnFileRmv));

    return cfg;
}
 
Example #30
Source File: IgniteExchangeLatchManagerDiscoHistoryTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    TcpDiscoveryIpFinder ipFinder = ((TcpDiscoverySpi)cfg.getDiscoverySpi()).getIpFinder();

    int topHistSize = victim ? TOPOLOGY_HISTORY_SIZE : TcpDiscoverySpi.DFLT_TOP_HISTORY_SIZE;

    CustomTcpDiscoverySpi discoSpi = new CustomTcpDiscoverySpi(topHistSize, ipFinder);

    cfg.setDiscoverySpi(discoSpi);

    if (victim) {
        cfg.setFailureHandler(new AbstractFailureHandler() {
            /** {@inheritDoc} */
            @Override protected boolean handle(Ignite ignite, FailureContext failureCtx) {
                cpFailureCtx.compareAndSet(null, failureCtx);

                // Invalidate kernel context.
                return true;
            }
        });

        cfg.setLifecycleBeans(lifecycleBean);

        disco = discoSpi;
    }

    return cfg;
}