Search in sources :

Example 16 with LongMetric

use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.

the class NodeSslConnectionMetricTest method testJdbc.

/**
 * Tests SSL metrics produced by JDBC connection.
 */
@Test
public void testJdbc() throws Exception {
    MetricRegistry reg = mreg(startClusterNode(0), CLIENT_CONNECTOR_METRICS);
    assertEquals(0, reg.<LongMetric>findMetric(SENT_BYTES_METRIC_NAME).value());
    assertEquals(0, reg.<LongMetric>findMetric(RECEIVED_BYTES_METRIC_NAME).value());
    try (Connection ignored = getConnection(jdbcConfiguration("thinClient", "trusttwo", CIPHER_SUITE, "TLSv1.2"))) {
        checkSslCommunicationMetrics(reg, 1, 1, 0);
    }
    assertTrue(reg.<LongMetric>findMetric(SENT_BYTES_METRIC_NAME).value() > 0);
    assertTrue(reg.<LongMetric>findMetric(RECEIVED_BYTES_METRIC_NAME).value() > 0);
    checkSslCommunicationMetrics(reg, 1, 0, 0);
    // Tests untrusted certificate.
    assertThrowsWithCause(() -> getConnection(jdbcConfiguration("client", "trusttwo", CIPHER_SUITE, "TLSv1.2")), SQLException.class);
    checkSslCommunicationMetrics(reg, 2, 0, 1);
    // Tests unsupported cipher suite.
    assertThrowsWithCause(() -> getConnection(jdbcConfiguration("thinClient", "trusttwo", UNSUPPORTED_CIPHER_SUITE, "TLSv1.2")), SQLException.class);
    checkSslCommunicationMetrics(reg, 3, 0, 2);
    assertThrowsWithCause(() -> getConnection(jdbcConfiguration("thinClient", "trusttwo", null, "TLSv1.1")), SQLException.class);
    checkSslCommunicationMetrics(reg, 4, 0, 3);
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) Connection(java.sql.Connection) DriverManager.getConnection(java.sql.DriverManager.getConnection) LongMetric(org.apache.ignite.spi.metric.LongMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 17 with LongMetric

use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.

the class NodeSslConnectionMetricTest method testClientConnector.

/**
 * Tests SSL metrics produced by thin client connection.
 */
@Test
public void testClientConnector() throws Exception {
    MetricRegistry reg = mreg(startClusterNode(0), CLIENT_CONNECTOR_METRICS);
    assertEquals(0, reg.<LongMetric>findMetric(SENT_BYTES_METRIC_NAME).value());
    assertEquals(0, reg.<LongMetric>findMetric(RECEIVED_BYTES_METRIC_NAME).value());
    try (IgniteClient ignored = startClient(clientConfiguration("thinClient", "trusttwo", CIPHER_SUITE, "TLSv1.2"))) {
        checkSslCommunicationMetrics(reg, 1, 1, 0);
    }
    assertTrue(reg.<LongMetric>findMetric(SENT_BYTES_METRIC_NAME).value() > 0);
    assertTrue(reg.<LongMetric>findMetric(RECEIVED_BYTES_METRIC_NAME).value() > 0);
    checkSslCommunicationMetrics(reg, 1, 0, 0);
    // Tests untrusted certificate.
    assertThrowsWithCause(() -> startClient(clientConfiguration("client", "trustboth", CIPHER_SUITE, "TLSv1.2")), ClientConnectionException.class);
    checkSslCommunicationMetrics(reg, 2, 0, 1);
    // Tests unsupported cipher suites.
    assertThrowsWithCause(() -> startClient(clientConfiguration("thinClient", "trusttwo", UNSUPPORTED_CIPHER_SUITE, "TLSv1.2")), ClientConnectionException.class);
    checkSslCommunicationMetrics(reg, 3, 0, 2);
    // Tests mismatched protocol versions.
    assertThrowsWithCause(() -> startClient(clientConfiguration("thinClient", "trusttwo", null, "TLSv1.1")), ClientConnectionException.class);
    checkSslCommunicationMetrics(reg, 4, 0, 3);
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 18 with LongMetric

use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.

the class NodeSslConnectionMetricTest method testRestClientConnector.

/**
 * Tests SSL metrics produced by REST TCP client connection.
 */
@Test
public void testRestClientConnector() throws Exception {
    MetricRegistry reg = mreg(startClusterNode(0), REST_CONNECTOR_METRIC_REGISTRY_NAME);
    assertEquals(0, reg.<LongMetric>findMetric(SENT_BYTES_METRIC_NAME).value());
    assertEquals(0, reg.<LongMetric>findMetric(RECEIVED_BYTES_METRIC_NAME).value());
    try (GridClient ignored = start(gridClientConfiguration("connectorClient", "trustthree", CIPHER_SUITE, "TLSv1.2"))) {
        checkSslCommunicationMetrics(reg, 1, 1, 0);
    }
    assertTrue(reg.<LongMetric>findMetric(SENT_BYTES_METRIC_NAME).value() > 0);
    assertTrue(reg.<LongMetric>findMetric(RECEIVED_BYTES_METRIC_NAME).value() > 0);
    checkSslCommunicationMetrics(reg, 1, 0, 0);
    // Tests untrusted certificate.
    try (GridClient ignored = start(gridClientConfiguration("client", "trustthree", CIPHER_SUITE, "TLSv1.2"))) {
    // GridClient makes 2 additional silent connection attempts if an SSL error occurs.
    }
    checkSslCommunicationMetrics(reg, 4, 0, 3);
    // Tests unsupported cipher suite.
    try (GridClient ignored = start(gridClientConfiguration("connectorClient", "trustthree", UNSUPPORTED_CIPHER_SUITE, "TLSv1.2"))) {
    // GridClient makes 2 additional silent connection attempts if an SSL error occurs.
    }
    checkSslCommunicationMetrics(reg, 7, 0, 6);
    // Tests mismatched protocol versions.
    try (GridClient ignored = start(gridClientConfiguration("connectorClient", "trustthree", null, "TLSv1.1"))) {
    // GridClient makes 2 additional  silent connection attempts if an SSL error occurs.
    }
    checkSslCommunicationMetrics(reg, 10, 0, 9);
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) GridClient(org.apache.ignite.internal.client.GridClient) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 19 with LongMetric

use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.

the class DiskPageCompressionIntegrationTest method doTestPageCompression.

/**
 * @throws Exception If failed.
 */
@Override
protected void doTestPageCompression() throws Exception {
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(true);
    String cacheName = "test";
    CacheConfiguration<Integer, TestVal> ccfg = new CacheConfiguration<Integer, TestVal>().setName(cacheName).setBackups(0).setAtomicityMode(ATOMIC).setIndexedTypes(Integer.class, TestVal.class).setDiskPageCompression(compression).setDiskPageCompressionLevel(compressionLevel);
    IgniteCache<Integer, TestVal> cache = ignite.getOrCreateCache(ccfg);
    int cnt = 2_000;
    for (int i = 0; i < cnt; i++) assertTrue(cache.putIfAbsent(i, new TestVal(i)));
    for (int i = 0; i < cnt; i += 2) assertEquals(new TestVal(i), cache.getAndRemove(i));
    GridCacheDatabaseSharedManager dbMgr = ((GridCacheDatabaseSharedManager) ignite.context().cache().context().database());
    dbMgr.forceCheckpoint("test compression").futureFor(FINISHED).get();
    FilePageStoreManager storeMgr = dbMgr.getFileStoreManager();
    checkFileIOFactory(storeMgr.getPageStoreFileIoFactory());
    // Wait for metrics update.
    Thread.sleep(100);
    long storeSize = ignite.dataStorageMetrics().getStorageSize();
    long sparseStoreSize = ignite.dataStorageMetrics().getSparseStorageSize();
    assertTrue("storeSize: " + storeSize, storeSize > 0);
    if (U.isLinux()) {
        assertTrue("sparseSize: " + sparseStoreSize, sparseStoreSize > 0);
        assertTrue(storeSize + " > " + sparseStoreSize, storeSize > sparseStoreSize);
    } else
        assertTrue(sparseStoreSize < 0);
    GridCacheContext<?, ?> cctx = ignite.cachex(cacheName).context();
    int cacheId = cctx.cacheId();
    int groupId = cctx.groupId();
    assertEquals(cacheId, groupId);
    MetricRegistry mreg = ignite.context().metric().registry(metricName(CACHE_GROUP_METRICS_PREFIX, cctx.group().cacheOrGroupName()));
    storeSize = mreg.<LongMetric>findMetric("StorageSize").value();
    sparseStoreSize = mreg.<LongMetric>findMetric("SparseStorageSize").value();
    assertTrue("storeSize: " + storeSize, storeSize > 0);
    if (U.isLinux()) {
        assertTrue("sparseSize: " + sparseStoreSize, sparseStoreSize > 0);
        assertTrue(storeSize + " > " + sparseStoreSize, storeSize > sparseStoreSize);
    } else
        assertTrue(sparseStoreSize < 0);
    int parts = cctx.affinity().partitions();
    for (int i = 0; i < parts; i++) {
        PageStore store = storeMgr.getStore(cacheId, i);
        long realSize = store.size();
        long virtualSize = store.getPageSize() * store.pages();
        long sparseSize = store.getSparseSize();
        assertTrue(virtualSize > 0);
        error("virt: " + virtualSize + ",  real: " + realSize + ",  sparse: " + sparseSize);
        if (!store.exists())
            continue;
        if (virtualSize > sparseSize)
            return;
    }
    fail("No files were compacted.");
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) LongMetric(org.apache.ignite.spi.metric.LongMetric) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 20 with LongMetric

use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.

the class CacheGroupsMetricsRebalanceTest method testRebalancingLastCancelledTime.

/**
 * @throws Exception If failed.
 */
@Test
public void testRebalancingLastCancelledTime() throws Exception {
    // Used for trigger rebalance cancellation.
    rebalanceDelay = REBALANCE_DELAY;
    IgniteEx ignite0 = startGrid(0);
    List<String> cacheNames = Arrays.asList(CACHE4, CACHE5);
    for (String cacheName : cacheNames) {
        ignite0.getOrCreateCache(cacheName).putAll(new Random().ints(KEYS_COUNT).distinct().boxed().collect(Collectors.toMap(i -> i, i -> (long) i)));
    }
    TestRecordingCommunicationSpi.spi(ignite0).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return (msg instanceof GridDhtPartitionSupplyMessage) && ((GridCacheGroupIdMessage) msg).groupId() == CU.cacheId(GROUP2);
        }
    });
    IgniteEx ignite1 = startGrid(1);
    TestRecordingCommunicationSpi.spi(ignite0).waitForBlocked();
    MetricRegistry mreg = ignite1.context().metric().registry(metricName(CACHE_GROUP_METRICS_PREFIX, GROUP2));
    LongMetric startTime = mreg.findMetric("RebalancingStartTime");
    LongMetric lastCancelledTime = mreg.findMetric("RebalancingLastCancelledTime");
    LongMetric endTime = mreg.findMetric("RebalancingEndTime");
    LongMetric partitionsLeft = mreg.findMetric("RebalancingPartitionsLeft");
    IntMetric partitionsTotal = mreg.findMetric("RebalancingPartitionsTotal");
    assertEquals("During the start of the rebalancing, the number of partitions in the metric should be " + "equal to the number of partitions in the cache group.", DFLT_PARTITION_COUNT, partitionsLeft.value());
    assertEquals("The total number of partitions in the metric should be " + "equal to the number of partitions in the cache group.", DFLT_PARTITION_COUNT, partitionsTotal.value());
    long rebalancingStartTime = startTime.value();
    assertNotSame("During rebalancing start, the start time metric must be determined.", -1, startTime.value());
    assertEquals("Rebalancing last cancelled time must be undefined.", -1, lastCancelledTime.value());
    assertEquals("Before the rebalancing is completed, the end time metric must be undefined.", -1, endTime.value());
    IgniteInternalFuture chain = ignite1.context().cache().internalCache(CACHE5).preloader().rebalanceFuture().chain(f -> {
        assertEquals("After the rebalancing is ended, the rebalancing start time must be equal to " + "the start time measured immediately after the rebalancing start.", rebalancingStartTime, startTime.value());
        assertEquals("If the rebalancing has been cancelled, the end time must not be set.", -1, endTime.value());
        return null;
    });
    TestRecordingCommunicationSpi.spi(ignite0).stopBlock(false);
    chain.get();
    assertNotSame("The rebalancing start time must not be equal to the previously measured start time, since" + " the first rebalancing was cancelled and restarted.", rebalancingStartTime, startTime.value());
    waitForCondition(() -> lastCancelledTime.value() != -1, 5000);
    assertTrue("The rebalancing last cancelled time must be greater than or equal to the start time of the " + "cancelled rebalancing [RebalancingStartTime=" + rebalancingStartTime + ", rebalancingLastCancelledTime=" + lastCancelledTime.value() + "].", rebalancingStartTime <= lastCancelledTime.value());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) IntMetric(org.apache.ignite.spi.metric.IntMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

LongMetric (org.apache.ignite.spi.metric.LongMetric)34 MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)27 Test (org.junit.Test)24 IgniteEx (org.apache.ignite.internal.IgniteEx)15 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)15 Ignite (org.apache.ignite.Ignite)7 List (java.util.List)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 ArrayList (java.util.ArrayList)5 IntMetric (org.apache.ignite.spi.metric.IntMetric)5 UUID (java.util.UUID)4 Metric (org.apache.ignite.spi.metric.Metric)4 File (java.io.File)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Function (java.util.function.Function)3 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)3 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3