public void testMetricsSize() {
    byte[] data = new byte[ClusterMetricsSnapshot.METRICS_SIZE];

    // Test serialization.
    int off = ClusterMetricsSnapshot.serialize(data, 0, createMetrics());

    assert off == ClusterMetricsSnapshot.METRICS_SIZE;

    // Test deserialization.
    ClusterMetrics res = ClusterMetricsSnapshot.deserialize(data, 0);

    assert res != null;
  }
  public void testSerialization() {
    byte[] data = new byte[ClusterMetricsSnapshot.METRICS_SIZE];

    ClusterMetrics metrics1 = createMetrics();

    // Test serialization.
    int off = ClusterMetricsSnapshot.serialize(data, 0, metrics1);

    assert off == ClusterMetricsSnapshot.METRICS_SIZE;

    // Test deserialization.
    ClusterMetrics metrics2 = ClusterMetricsSnapshot.deserialize(data, 0);

    assert metrics2 != null;

    assert isMetricsEquals(metrics1, metrics2);
  }
  /** @return Test metrics. */
  private ClusterMetrics createMetrics() {
    ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot();

    metrics.setAvailableProcessors(1);
    metrics.setAverageActiveJobs(2);
    metrics.setAverageCancelledJobs(3);
    metrics.setAverageJobExecuteTime(4);
    metrics.setAverageJobWaitTime(5);
    metrics.setAverageRejectedJobs(6);
    metrics.setAverageWaitingJobs(7);
    metrics.setCurrentActiveJobs(8);
    metrics.setCurrentCancelledJobs(9);
    metrics.setCurrentIdleTime(10);
    metrics.setCurrentIdleTime(11);
    metrics.setCurrentJobExecuteTime(12);
    metrics.setCurrentJobWaitTime(13);
    metrics.setCurrentRejectedJobs(14);
    metrics.setCurrentWaitingJobs(15);
    metrics.setCurrentDaemonThreadCount(16);
    metrics.setHeapMemoryCommitted(17);
    metrics.setHeapMemoryInitialized(18);
    metrics.setHeapMemoryMaximum(19);
    metrics.setHeapMemoryUsed(20);
    metrics.setLastUpdateTime(21);
    metrics.setMaximumActiveJobs(22);
    metrics.setMaximumCancelledJobs(23);
    metrics.setMaximumJobExecuteTime(24);
    metrics.setMaximumJobWaitTime(25);
    metrics.setMaximumRejectedJobs(26);
    metrics.setMaximumWaitingJobs(27);
    metrics.setNonHeapMemoryCommitted(28);
    metrics.setNonHeapMemoryInitialized(29);
    metrics.setNonHeapMemoryMaximum(30);
    metrics.setNonHeapMemoryUsed(31);
    metrics.setMaximumThreadCount(32);
    metrics.setStartTime(33);
    metrics.setCurrentCpuLoad(34);
    metrics.setCurrentThreadCount(35);
    metrics.setTotalCancelledJobs(36);
    metrics.setTotalExecutedJobs(37);
    metrics.setTotalIdleTime(38);
    metrics.setTotalRejectedJobs(39);
    metrics.setTotalStartedThreadCount(40);
    metrics.setUpTime(41);
    metrics.setSentMessagesCount(42);
    metrics.setSentBytesCount(43);
    metrics.setReceivedMessagesCount(44);
    metrics.setReceivedBytesCount(45);
    metrics.setOutboundMessagesQueueSize(46);
    metrics.setNonHeapMemoryTotal(47);
    metrics.setHeapMemoryTotal(48);

    return metrics;
  }
  /** Checks compatibility with old serialized metrics. */
  public void testMetricsCompatibility() {
    ClusterMetrics metrics = ClusterMetricsSnapshot.deserialize(METRICS_V1, 0);

    assert metrics != null;
  }