Search in sources :

Example 36 with AtomicConfiguration

use of org.apache.ignite.configuration.AtomicConfiguration in project ignite by apache.

the class PlatformConfigurationUtils method readIgniteConfiguration.

/**
 * Reads Ignite configuration.
 * @param in Reader.
 * @param cfg Configuration.
 */
@SuppressWarnings("deprecation")
public static void readIgniteConfiguration(BinaryRawReaderEx in, IgniteConfiguration cfg) {
    if (in.readBoolean())
        cfg.setClientMode(in.readBoolean());
    int[] evtTypes = in.readIntArray();
    if (evtTypes != null)
        cfg.setIncludeEventTypes(evtTypes);
    if (in.readBoolean())
        cfg.setMetricsExpireTime(in.readLong());
    if (in.readBoolean())
        cfg.setMetricsHistorySize(in.readInt());
    if (in.readBoolean())
        cfg.setMetricsLogFrequency(in.readLong());
    if (in.readBoolean())
        cfg.setMetricsUpdateFrequency(in.readLong());
    if (in.readBoolean())
        cfg.setNetworkSendRetryCount(in.readInt());
    if (in.readBoolean())
        cfg.setNetworkSendRetryDelay(in.readLong());
    if (in.readBoolean())
        cfg.setNetworkTimeout(in.readLong());
    String workDir = in.readString();
    if (workDir != null)
        cfg.setWorkDirectory(workDir);
    String locHost = in.readString();
    if (locHost != null)
        cfg.setLocalHost(locHost);
    if (in.readBoolean())
        cfg.setDaemon(in.readBoolean());
    if (in.readBoolean())
        cfg.setFailureDetectionTimeout(in.readLong());
    if (in.readBoolean())
        cfg.setClientFailureDetectionTimeout(in.readLong());
    if (in.readBoolean())
        cfg.setLongQueryWarningTimeout(in.readLong());
    if (in.readBoolean())
        cfg.setActiveOnStart(in.readBoolean());
    if (in.readBoolean())
        cfg.setAuthenticationEnabled(in.readBoolean());
    if (in.readBoolean())
        cfg.setMvccVacuumFrequency(in.readLong());
    if (in.readBoolean())
        cfg.setMvccVacuumThreadCount(in.readInt());
    if (in.readBoolean())
        cfg.setSystemWorkerBlockedTimeout(in.readLong());
    if (in.readBoolean())
        cfg.setSqlQueryHistorySize(in.readInt());
    if (in.readBoolean())
        cfg.setPeerClassLoadingEnabled(in.readBoolean());
    if (in.readBoolean())
        cfg.setAsyncContinuationExecutor(getAsyncContinuationExecutor(in.readInt()));
    int sqlSchemasCnt = in.readInt();
    if (sqlSchemasCnt >= 0) {
        String[] sqlSchemas = new String[sqlSchemasCnt];
        for (int i = 0; i < sqlSchemasCnt; i++) sqlSchemas[i] = in.readString();
        cfg.setSqlSchemas(sqlSchemas);
    }
    Object consId = in.readObjectDetached();
    if (consId instanceof Serializable) {
        cfg.setConsistentId((Serializable) consId);
    } else if (consId != null) {
        throw new IgniteException("IgniteConfiguration.ConsistentId should be Serializable.");
    }
    // Thread pools.
    if (in.readBoolean())
        cfg.setPublicThreadPoolSize(in.readInt());
    if (in.readBoolean())
        cfg.setStripedPoolSize(in.readInt());
    if (in.readBoolean())
        cfg.setServiceThreadPoolSize(in.readInt());
    if (in.readBoolean())
        cfg.setSystemThreadPoolSize(in.readInt());
    if (in.readBoolean())
        cfg.setAsyncCallbackPoolSize(in.readInt());
    if (in.readBoolean())
        cfg.setManagementThreadPoolSize(in.readInt());
    if (in.readBoolean())
        cfg.setDataStreamerThreadPoolSize(in.readInt());
    if (in.readBoolean())
        cfg.setUtilityCachePoolSize(in.readInt());
    if (in.readBoolean())
        cfg.setQueryThreadPoolSize(in.readInt());
    readCacheConfigurations(in, cfg);
    readDiscoveryConfiguration(in, cfg);
    readEncryptionConfiguration(in, cfg);
    if (in.readBoolean()) {
        TcpCommunicationSpi comm = new TcpCommunicationSpi();
        comm.setAckSendThreshold(in.readInt());
        comm.setConnectionsPerNode(in.readInt());
        comm.setConnectTimeout(in.readLong());
        comm.setDirectBuffer(in.readBoolean());
        comm.setDirectSendBuffer(in.readBoolean());
        comm.setFilterReachableAddresses(in.readBoolean());
        comm.setIdleConnectionTimeout(in.readLong());
        comm.setLocalAddress(in.readString());
        comm.setLocalPort(in.readInt());
        comm.setLocalPortRange(in.readInt());
        comm.setMaxConnectTimeout(in.readLong());
        comm.setMessageQueueLimit(in.readInt());
        comm.setReconnectCount(in.readInt());
        comm.setSelectorsCount(in.readInt());
        comm.setSelectorSpins(in.readLong());
        comm.setSharedMemoryPort(in.readInt());
        comm.setSlowClientQueueLimit(in.readInt());
        comm.setSocketReceiveBuffer(in.readInt());
        comm.setSocketSendBuffer(in.readInt());
        comm.setSocketWriteTimeout(in.readLong());
        comm.setTcpNoDelay(in.readBoolean());
        comm.setUnacknowledgedMessagesBufferSize(in.readInt());
        comm.setUsePairedConnections(in.readBoolean());
        cfg.setCommunicationSpi(comm);
    }
    if (in.readBoolean()) {
        // binary config is present
        if (cfg.getBinaryConfiguration() == null)
            cfg.setBinaryConfiguration(new BinaryConfiguration());
        if (// compact footer is set
        in.readBoolean())
            cfg.getBinaryConfiguration().setCompactFooter(in.readBoolean());
        if (in.readBoolean()) {
            // Simple name mapper.
            cfg.getBinaryConfiguration().setNameMapper(new BinaryBasicNameMapper(true));
        }
    }
    int attrCnt = in.readInt();
    if (attrCnt > 0) {
        Map<String, Object> attrs = new HashMap<>(attrCnt);
        for (int i = 0; i < attrCnt; i++) attrs.put(in.readString(), in.readObject());
        cfg.setUserAttributes(attrs);
    }
    if (in.readBoolean()) {
        AtomicConfiguration atomic = new AtomicConfiguration();
        atomic.setAtomicSequenceReserveSize(in.readInt());
        atomic.setBackups(in.readInt());
        atomic.setCacheMode(CacheMode.fromOrdinal(in.readInt()));
        cfg.setAtomicConfiguration(atomic);
    }
    if (in.readBoolean()) {
        TransactionConfiguration tx = new TransactionConfiguration();
        tx.setPessimisticTxLogSize(in.readInt());
        tx.setDefaultTxConcurrency(TransactionConcurrency.fromOrdinal(in.readInt()));
        tx.setDefaultTxIsolation(TransactionIsolation.fromOrdinal(in.readInt()));
        tx.setDefaultTxTimeout(in.readLong());
        tx.setPessimisticTxLogLinger(in.readInt());
        tx.setTxTimeoutOnPartitionMapExchange(in.readLong());
        tx.setDeadlockTimeout(in.readLong());
        cfg.setTransactionConfiguration(tx);
    }
    switch(in.readByte()) {
        case 1:
            cfg.setEventStorageSpi(new NoopEventStorageSpi());
            break;
        case 2:
            cfg.setEventStorageSpi(new MemoryEventStorageSpi().setExpireCount(in.readLong()).setExpireAgeMs(in.readLong()));
            break;
    }
    if (in.readBoolean())
        cfg.setMemoryConfiguration(readMemoryConfiguration(in));
    if (in.readBoolean())
        cfg.setSqlConnectorConfiguration(readSqlConnectorConfiguration(in));
    if (in.readBoolean())
        cfg.setClientConnectorConfiguration(readClientConnectorConfiguration(in));
    if (// ClientConnectorConfigurationEnabled override
    !in.readBoolean())
        cfg.setClientConnectorConfiguration(null);
    if (in.readBoolean())
        cfg.setPersistentStoreConfiguration(readPersistentStoreConfiguration(in));
    if (in.readBoolean())
        cfg.setDataStorageConfiguration(readDataStorageConfiguration(in));
    if (in.readBoolean())
        cfg.setSslContextFactory(readSslContextFactory(in));
    if (in.readBoolean()) {
        switch(in.readByte()) {
            case 0:
                cfg.setFailureHandler(new NoOpFailureHandler());
                break;
            case 1:
                cfg.setFailureHandler(new StopNodeFailureHandler());
                break;
            case 2:
                cfg.setFailureHandler(new StopNodeOrHaltFailureHandler(in.readBoolean(), in.readLong()));
                break;
        }
    }
    int execCfgCnt = in.readInt();
    if (execCfgCnt > 0) {
        ExecutorConfiguration[] execCfgs = new ExecutorConfiguration[execCfgCnt];
        for (int i = 0; i < execCfgCnt; i++) {
            execCfgs[i] = new ExecutorConfiguration().setName(in.readString()).setSize(in.readInt());
        }
        cfg.setExecutorConfiguration(execCfgs);
    }
    readPluginConfiguration(cfg, in);
    readLocalEventListeners(cfg, in);
}
Also used : NoOpFailureHandler(org.apache.ignite.failure.NoOpFailureHandler) Serializable(java.io.Serializable) TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) StopNodeOrHaltFailureHandler(org.apache.ignite.failure.StopNodeOrHaltFailureHandler) MemoryEventStorageSpi(org.apache.ignite.spi.eventstorage.memory.MemoryEventStorageSpi) StopNodeFailureHandler(org.apache.ignite.failure.StopNodeFailureHandler) NoopEventStorageSpi(org.apache.ignite.spi.eventstorage.NoopEventStorageSpi) ExecutorConfiguration(org.apache.ignite.configuration.ExecutorConfiguration) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) PlatformDotNetBinaryConfiguration(org.apache.ignite.platform.dotnet.PlatformDotNetBinaryConfiguration) IgniteException(org.apache.ignite.IgniteException) AtomicConfiguration(org.apache.ignite.configuration.AtomicConfiguration)

Example 37 with AtomicConfiguration

use of org.apache.ignite.configuration.AtomicConfiguration in project ignite by apache.

the class PlatformConfigurationUtils method writeIgniteConfiguration.

/**
 * Writes Ignite configuration.
 *
 * @param w Writer.
 * @param cfg Configuration.
 */
@SuppressWarnings("deprecation")
public static void writeIgniteConfiguration(BinaryRawWriter w, IgniteConfiguration cfg) {
    assert w != null;
    assert cfg != null;
    w.writeBoolean(true);
    w.writeBoolean(cfg.isClientMode());
    w.writeIntArray(cfg.getIncludeEventTypes());
    w.writeBoolean(true);
    w.writeLong(cfg.getMetricsExpireTime());
    w.writeBoolean(true);
    w.writeInt(cfg.getMetricsHistorySize());
    w.writeBoolean(true);
    w.writeLong(cfg.getMetricsLogFrequency());
    w.writeBoolean(true);
    w.writeLong(cfg.getMetricsUpdateFrequency());
    w.writeBoolean(true);
    w.writeInt(cfg.getNetworkSendRetryCount());
    w.writeBoolean(true);
    w.writeLong(cfg.getNetworkSendRetryDelay());
    w.writeBoolean(true);
    w.writeLong(cfg.getNetworkTimeout());
    w.writeString(cfg.getWorkDirectory());
    w.writeString(cfg.getLocalHost());
    w.writeBoolean(true);
    w.writeBoolean(cfg.isDaemon());
    w.writeBoolean(true);
    w.writeLong(cfg.getFailureDetectionTimeout());
    w.writeBoolean(true);
    w.writeLong(cfg.getClientFailureDetectionTimeout());
    w.writeBoolean(true);
    w.writeLong(cfg.getLongQueryWarningTimeout());
    w.writeBoolean(true);
    w.writeBoolean(cfg.isActiveOnStart());
    w.writeBoolean(true);
    w.writeBoolean(cfg.isAuthenticationEnabled());
    w.writeBoolean(true);
    w.writeLong(cfg.getMvccVacuumFrequency());
    w.writeBoolean(true);
    w.writeInt(cfg.getMvccVacuumThreadCount());
    if (cfg.getSystemWorkerBlockedTimeout() != null) {
        w.writeBoolean(true);
        w.writeLong(cfg.getSystemWorkerBlockedTimeout());
    } else {
        w.writeBoolean(false);
    }
    w.writeBoolean(true);
    w.writeInt(cfg.getSqlQueryHistorySize());
    w.writeBoolean(true);
    w.writeBoolean(cfg.isPeerClassLoadingEnabled());
    w.writeBoolean(true);
    w.writeInt(getAsyncContinuationExecutorMode(cfg.getAsyncContinuationExecutor()));
    if (cfg.getSqlSchemas() == null)
        w.writeInt(0);
    else {
        w.writeInt(cfg.getSqlSchemas().length);
        for (String schema : cfg.getSqlSchemas()) w.writeString(schema);
    }
    w.writeObject(cfg.getConsistentId());
    // Thread pools.
    w.writeBoolean(true);
    w.writeInt(cfg.getPublicThreadPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getStripedPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getServiceThreadPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getSystemThreadPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getAsyncCallbackPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getManagementThreadPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getDataStreamerThreadPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getUtilityCacheThreadPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getQueryThreadPoolSize());
    CacheConfiguration[] cacheCfg = cfg.getCacheConfiguration();
    if (cacheCfg != null) {
        w.writeInt(cacheCfg.length);
        for (CacheConfiguration ccfg : cacheCfg) writeCacheConfiguration(w, ccfg);
    } else
        w.writeInt(0);
    writeDiscoveryConfiguration(w, cfg.getDiscoverySpi());
    writeEncryptionConfiguration(w, cfg.getEncryptionSpi());
    CommunicationSpi comm = cfg.getCommunicationSpi();
    if (comm instanceof TcpCommunicationSpi) {
        w.writeBoolean(true);
        TcpCommunicationSpi tcp = (TcpCommunicationSpi) comm;
        w.writeInt(tcp.getAckSendThreshold());
        w.writeInt(tcp.getConnectionsPerNode());
        w.writeLong(tcp.getConnectTimeout());
        w.writeBoolean(tcp.isDirectBuffer());
        w.writeBoolean(tcp.isDirectSendBuffer());
        w.writeBoolean(tcp.isFilterReachableAddresses());
        w.writeLong(tcp.getIdleConnectionTimeout());
        w.writeString(tcp.getLocalAddress());
        w.writeInt(tcp.getLocalPort());
        w.writeInt(tcp.getLocalPortRange());
        w.writeLong(tcp.getMaxConnectTimeout());
        w.writeInt(tcp.getMessageQueueLimit());
        w.writeInt(tcp.getReconnectCount());
        w.writeInt(tcp.getSelectorsCount());
        w.writeLong(tcp.getSelectorSpins());
        w.writeInt(tcp.getSharedMemoryPort());
        w.writeInt(tcp.getSlowClientQueueLimit());
        w.writeInt(tcp.getSocketReceiveBuffer());
        w.writeInt(tcp.getSocketSendBuffer());
        w.writeLong(tcp.getSocketWriteTimeout());
        w.writeBoolean(tcp.isTcpNoDelay());
        w.writeInt(tcp.getUnacknowledgedMessagesBufferSize());
        w.writeBoolean(tcp.isUsePairedConnections());
    } else
        w.writeBoolean(false);
    BinaryConfiguration bc = cfg.getBinaryConfiguration();
    if (bc != null) {
        // binary config exists
        w.writeBoolean(true);
        // compact footer is set
        w.writeBoolean(true);
        w.writeBoolean(bc.isCompactFooter());
        w.writeBoolean(bc.getNameMapper() instanceof BinaryBasicNameMapper && ((BinaryBasicNameMapper) (bc.getNameMapper())).isSimpleName());
    } else
        w.writeBoolean(false);
    Map<String, ?> attrs = cfg.getUserAttributes();
    if (attrs != null) {
        w.writeInt(attrs.size());
        for (Map.Entry<String, ?> e : attrs.entrySet()) {
            w.writeString(e.getKey());
            w.writeObject(e.getValue());
        }
    } else
        w.writeInt(0);
    AtomicConfiguration atomic = cfg.getAtomicConfiguration();
    if (atomic != null) {
        w.writeBoolean(true);
        w.writeInt(atomic.getAtomicSequenceReserveSize());
        w.writeInt(atomic.getBackups());
        writeEnumInt(w, atomic.getCacheMode(), AtomicConfiguration.DFLT_CACHE_MODE);
    } else
        w.writeBoolean(false);
    TransactionConfiguration tx = cfg.getTransactionConfiguration();
    if (tx != null) {
        w.writeBoolean(true);
        w.writeInt(tx.getPessimisticTxLogSize());
        writeEnumInt(w, tx.getDefaultTxConcurrency(), TransactionConfiguration.DFLT_TX_CONCURRENCY);
        writeEnumInt(w, tx.getDefaultTxIsolation(), TransactionConfiguration.DFLT_TX_ISOLATION);
        w.writeLong(tx.getDefaultTxTimeout());
        w.writeInt(tx.getPessimisticTxLogLinger());
        w.writeLong(tx.getTxTimeoutOnPartitionMapExchange());
        w.writeLong(tx.getDeadlockTimeout());
    } else
        w.writeBoolean(false);
    EventStorageSpi evtStorageSpi = cfg.getEventStorageSpi();
    if (evtStorageSpi == null)
        w.writeByte((byte) 0);
    else if (evtStorageSpi instanceof NoopEventStorageSpi)
        w.writeByte((byte) 1);
    else if (evtStorageSpi instanceof MemoryEventStorageSpi) {
        w.writeByte((byte) 2);
        w.writeLong(((MemoryEventStorageSpi) evtStorageSpi).getExpireCount());
        w.writeLong(((MemoryEventStorageSpi) evtStorageSpi).getExpireAgeMs());
    }
    writeMemoryConfiguration(w, cfg.getMemoryConfiguration());
    writeSqlConnectorConfiguration(w, cfg.getSqlConnectorConfiguration());
    writeClientConnectorConfiguration(w, cfg.getClientConnectorConfiguration());
    w.writeBoolean(cfg.getClientConnectorConfiguration() != null);
    writePersistentStoreConfiguration(w, cfg.getPersistentStoreConfiguration());
    writeDataStorageConfiguration(w, cfg.getDataStorageConfiguration());
    writeSslContextFactory(w, cfg.getSslContextFactory());
    FailureHandler failureHnd = cfg.getFailureHandler();
    if (failureHnd instanceof NoOpFailureHandler) {
        w.writeBoolean(true);
        w.writeByte((byte) 0);
    } else if (failureHnd instanceof StopNodeFailureHandler) {
        w.writeBoolean(true);
        w.writeByte((byte) 1);
    } else if (failureHnd instanceof StopNodeOrHaltFailureHandler) {
        w.writeBoolean(true);
        w.writeByte((byte) 2);
        w.writeBoolean(((StopNodeOrHaltFailureHandler) failureHnd).tryStop());
        w.writeLong(((StopNodeOrHaltFailureHandler) failureHnd).timeout());
    } else
        w.writeBoolean(false);
    ExecutorConfiguration[] execCfgs = cfg.getExecutorConfiguration();
    if (execCfgs != null) {
        w.writeInt(execCfgs.length);
        for (ExecutorConfiguration execCfg : execCfgs) {
            w.writeString(execCfg.getName());
            w.writeInt(execCfg.getSize());
        }
    } else
        w.writeInt(0);
    w.writeString(cfg.getIgniteHome());
    w.writeLong(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getInit());
    w.writeLong(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax());
}
Also used : NoOpFailureHandler(org.apache.ignite.failure.NoOpFailureHandler) TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) StopNodeOrHaltFailureHandler(org.apache.ignite.failure.StopNodeOrHaltFailureHandler) StopNodeFailureHandler(org.apache.ignite.failure.StopNodeFailureHandler) NoOpFailureHandler(org.apache.ignite.failure.NoOpFailureHandler) FailureHandler(org.apache.ignite.failure.FailureHandler) StopNodeOrHaltFailureHandler(org.apache.ignite.failure.StopNodeOrHaltFailureHandler) EventStorageSpi(org.apache.ignite.spi.eventstorage.EventStorageSpi) NoopEventStorageSpi(org.apache.ignite.spi.eventstorage.NoopEventStorageSpi) MemoryEventStorageSpi(org.apache.ignite.spi.eventstorage.memory.MemoryEventStorageSpi) MemoryEventStorageSpi(org.apache.ignite.spi.eventstorage.memory.MemoryEventStorageSpi) StopNodeFailureHandler(org.apache.ignite.failure.StopNodeFailureHandler) NoopEventStorageSpi(org.apache.ignite.spi.eventstorage.NoopEventStorageSpi) ExecutorConfiguration(org.apache.ignite.configuration.ExecutorConfiguration) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) PlatformDotNetBinaryConfiguration(org.apache.ignite.platform.dotnet.PlatformDotNetBinaryConfiguration) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) AtomicConfiguration(org.apache.ignite.configuration.AtomicConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) PlatformCacheConfiguration(org.apache.ignite.configuration.PlatformCacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 38 with AtomicConfiguration

use of org.apache.ignite.configuration.AtomicConfiguration in project ignite by apache.

the class IgniteClientReconnectAtomicsWithLostPartitionsTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    String consistentId = "consistent-id-" + igniteInstanceName.charAt(igniteInstanceName.length() - 1);
    cfg.setConsistentId(consistentId);
    AtomicConfiguration atomicCfg = new AtomicConfiguration().setBackups(0).setAffinity(new RendezvousAffinityFunction(false, 32));
    cfg.setAtomicConfiguration(atomicCfg);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) AtomicConfiguration(org.apache.ignite.configuration.AtomicConfiguration)

Example 39 with AtomicConfiguration

use of org.apache.ignite.configuration.AtomicConfiguration in project ignite by apache.

the class SystemViewSelfTest method testAtomicStamped.

/**
 */
@Test
public void testAtomicStamped() throws Exception {
    try (IgniteEx g0 = startGrid(0);
        IgniteEx g1 = startGrid(1)) {
        IgniteAtomicStamped<String, Integer> s1 = g0.atomicStamped("s-1", "str0", 1, true);
        IgniteAtomicStamped<String, Integer> s2 = g0.atomicStamped("s-2", new AtomicConfiguration().setBackups(1).setGroupName("my-group"), "str1", 43, true);
        SystemView<AtomicStampedView> stamps0 = g0.context().systemView().view(STAMPED_VIEW);
        SystemView<AtomicStampedView> stamps1 = g1.context().systemView().view(STAMPED_VIEW);
        assertEquals(2, stamps0.size());
        assertEquals(0, stamps1.size());
        for (AtomicStampedView s : stamps0) {
            if ("s-1".equals(s.name())) {
                assertEquals("str0", s.value());
                assertEquals("1", s.stamp());
                assertEquals(DEFAULT_DS_GROUP_NAME, s.groupName());
                assertEquals(CU.cacheId(DEFAULT_DS_GROUP_NAME), s.groupId());
                s1.set("str2", 2);
                assertEquals("str2", s.value());
                assertEquals("2", s.stamp());
                assertFalse(s.removed());
            } else {
                assertEquals("s-2", s.name());
                assertEquals("str1", s.value());
                assertEquals("43", s.stamp());
                assertEquals("my-group", s.groupName());
                assertEquals(CU.cacheId("my-group"), s.groupId());
                assertFalse(s.removed());
                s2.close();
                assertTrue(waitForCondition(s::removed, getTestTimeout()));
            }
        }
        g1.atomicStamped("s-1", "str3", 3, true);
        assertEquals(1, stamps1.size());
        AtomicStampedView l = stamps1.iterator().next();
        assertEquals("str2", l.value());
        assertEquals("2", l.stamp());
        assertEquals(DEFAULT_DS_GROUP_NAME, l.groupName());
        assertEquals(CU.cacheId(DEFAULT_DS_GROUP_NAME), l.groupId());
        assertFalse(l.removed());
        s1.close();
        assertTrue(l.removed());
        assertEquals(0, stamps0.size());
        assertEquals(0, stamps1.size());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) AtomicStampedView(org.apache.ignite.spi.systemview.view.datastructures.AtomicStampedView) AtomicConfiguration(org.apache.ignite.configuration.AtomicConfiguration) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Example 40 with AtomicConfiguration

use of org.apache.ignite.configuration.AtomicConfiguration in project ignite by apache.

the class SystemViewSelfTest method testAtomicLongs.

/**
 */
@Test
public void testAtomicLongs() throws Exception {
    try (IgniteEx g0 = startGrid(0);
        IgniteEx g1 = startGrid(1)) {
        IgniteAtomicLong l1 = g0.atomicLong("long-1", 42, true);
        IgniteAtomicLong l2 = g0.atomicLong("long-2", new AtomicConfiguration().setBackups(1).setGroupName("my-group"), 43, true);
        SystemView<AtomicLongView> longs0 = g0.context().systemView().view(LONGS_VIEW);
        SystemView<AtomicLongView> longs1 = g1.context().systemView().view(LONGS_VIEW);
        assertEquals(2, longs0.size());
        assertEquals(0, longs1.size());
        for (AtomicLongView l : longs0) {
            if ("long-1".equals(l.name())) {
                assertEquals(42, l.value());
                assertEquals(DEFAULT_DS_GROUP_NAME, l.groupName());
                assertEquals(CU.cacheId(DEFAULT_DS_GROUP_NAME), l.groupId());
                long val = l1.addAndGet(42);
                assertEquals(val, l.value());
                assertFalse(l.removed());
            } else {
                assertEquals("long-2", l.name());
                assertEquals(43, l.value());
                assertEquals("my-group", l.groupName());
                assertEquals(CU.cacheId("my-group"), l.groupId());
                assertFalse(l.removed());
                l2.close();
                assertTrue(waitForCondition(l::removed, getTestTimeout()));
            }
        }
        g1.atomicLong("long-1", 42, true);
        assertEquals(1, longs1.size());
        AtomicLongView l = longs1.iterator().next();
        assertEquals(84, l.value());
        assertEquals(DEFAULT_DS_GROUP_NAME, l.groupName());
        assertEquals(CU.cacheId(DEFAULT_DS_GROUP_NAME), l.groupId());
        assertFalse(l.removed());
        l1.close();
        assertTrue(waitForCondition(l::removed, getTestTimeout()));
        assertEquals(0, longs0.size());
        assertEquals(0, longs1.size());
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) AtomicConfiguration(org.apache.ignite.configuration.AtomicConfiguration) AtomicLongView(org.apache.ignite.spi.systemview.view.datastructures.AtomicLongView) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Aggregations

AtomicConfiguration (org.apache.ignite.configuration.AtomicConfiguration)43 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)14 Test (org.junit.Test)11 Ignite (org.apache.ignite.Ignite)7 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)7 IgniteAtomicSequence (org.apache.ignite.IgniteAtomicSequence)5 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)5 IgniteEx (org.apache.ignite.internal.IgniteEx)5 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)5 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 HashMap (java.util.HashMap)3 IgniteAtomicLong (org.apache.ignite.IgniteAtomicLong)3 LruEvictionPolicy (org.apache.ignite.cache.eviction.lru.LruEvictionPolicy)3 LinkedHashMap (java.util.LinkedHashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 BinaryBasicNameMapper (org.apache.ignite.binary.BinaryBasicNameMapper)2 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)2 ExecutorConfiguration (org.apache.ignite.configuration.ExecutorConfiguration)2 TransactionConfiguration (org.apache.ignite.configuration.TransactionConfiguration)2 NoOpFailureHandler (org.apache.ignite.failure.NoOpFailureHandler)2