ss: Add class to serialize/deserialize a statedump
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.statesystem.core.tests / src / org / eclipse / tracecompass / statesystem / core / tests / StatedumpTest.java
CommitLineData
51a8fbff
AM
1/*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10package org.eclipse.tracecompass.statesystem.core.tests;
11
12import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
13import static org.junit.Assert.assertArrayEquals;
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertNotNull;
16import static org.junit.Assert.fail;
17
18import java.io.IOException;
19import java.nio.file.Files;
20import java.nio.file.Path;
21import java.util.Arrays;
22import java.util.List;
23
24import org.apache.commons.io.FileUtils;
25import org.eclipse.jdt.annotation.NonNull;
26import org.eclipse.tracecompass.statesystem.core.Statedump;
27import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
28import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
29import org.junit.Test;
30
31/**
32 * Tests for {@link Statedump}.
33 *
34 * @author Alexandre Montplaisir
35 */
36public class StatedumpTest {
37
38 /**
39 * Test that a manually-written statedump is serialized then read correctly.
40 */
41 @Test
42 public void testSimpleStatedump() {
43 Path dir = null;
44 try {
45 dir = checkNotNull(Files.createTempDirectory("ss-serialization-test"));
46 String ssid = "test-ssid";
47 final int nbAttributes = 6;
48 final int version = 0;
49
50 List<String @NonNull []> initialAttributes = Arrays.asList(
51 new String[] { "Threads" },
52 new String[] { "Threads", "1000" },
53 new String[] { "Threads", "1000", "Status" },
54 new String[] { "Threads", "2000" },
55 new String[] { "Threads", "2000", "Status" },
56 new String[] { "Threads", "2000", "PPID" });
57
58 List<@NonNull ITmfStateValue> initialValues = Arrays.asList(
59 TmfStateValue.nullValue(),
60 TmfStateValue.nullValue(),
61 TmfStateValue.newValueString("Running"),
62 TmfStateValue.nullValue(),
63 TmfStateValue.newValueInt(1),
64 TmfStateValue.newValueLong(1000L));
65
66 Statedump statedump = new Statedump(initialAttributes, initialValues, version);
67 statedump.dumpState(dir, ssid);
68
69 Statedump results = Statedump.loadState(dir, ssid);
70 assertNotNull(results);
71
72 assertEquals(version, results.getVersion());
73
74 List<String[]> newAttributes = results.getAttributes();
75 List<ITmfStateValue> newValues = results.getStates();
76 assertEquals(nbAttributes, newAttributes.size());
77 assertEquals(nbAttributes, newValues.size());
78
79 for (int i = 0; i < nbAttributes; i++) {
80 assertArrayEquals(initialAttributes.get(i), newAttributes.get(i));
81 assertEquals(initialValues.get(i), newValues.get(i));
82 }
83
84 } catch (IOException e) {
85 fail(e.getMessage());
86
87 } finally {
88 if (dir != null) {
89 FileUtils.deleteQuietly(dir.toFile());
90 }
91 }
92 }
93}
This page took 0.027619 seconds and 5 git commands to generate.