ss: Move all debugPrint() methods to the test stubs
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Mon, 19 Sep 2016 18:42:08 +0000 (14:42 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Tue, 20 Sep 2016 01:33:45 +0000 (21:33 -0400)
Where they belong!

Change-Id: Ie6f176f1f16962ab64a8faf40c79548d82d1234b
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/81378
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Reviewed-by: Hudson CI
12 files changed:
statesystem/org.eclipse.tracecompass.statesystem.core.tests/stubs/org/eclipse/tracecompass/statesystem/core/tests/stubs/backend/HistoryTreeBackendStub.java
statesystem/org.eclipse.tracecompass.statesystem.core.tests/stubs/org/eclipse/tracecompass/statesystem/core/tests/stubs/backend/HistoryTreeClassicStub.java
statesystem/org.eclipse.tracecompass.statesystem.core/.settings/.api_filters [new file with mode: 0644]
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/internal/statesystem/core/StateSystem.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/internal/statesystem/core/backend/InMemoryBackend.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/internal/statesystem/core/backend/NullBackend.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/internal/statesystem/core/backend/historytree/HT_IO.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/internal/statesystem/core/backend/historytree/HistoryTreeBackend.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/internal/statesystem/core/backend/historytree/HistoryTreeClassic.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/internal/statesystem/core/backend/historytree/IHistoryTree.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/statesystem/core/backend/IStateHistoryBackend.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/statesystem/backends/partial/PartialHistoryBackend.java

index 0aa13f6a5b26d0a6b936388def196b20cd199980..ede7014b0efd63f4712ee9974e76237bb087dfd2 100644 (file)
@@ -11,6 +11,7 @@ package org.eclipse.tracecompass.statesystem.core.tests.stubs.backend;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.PrintWriter;
 
 import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HTConfig;
 import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HistoryTreeBackend;
@@ -129,4 +130,41 @@ public class HistoryTreeBackendStub extends HistoryTreeBackend {
         return (HistoryTreeClassicStub) super.getSHT();
     }
 
+    /**
+     * Debug method to print the contents of the history backend.
+     *
+     * @param writer
+     *            The PrintWriter where to write the output
+     */
+    public void debugPrint(PrintWriter writer) {
+        /* By default don't print out all the intervals */
+        debugPrint(writer, false, -1);
+    }
+
+    /**
+     * The basic debugPrint method will print the tree structure, but not their
+     * contents.
+     *
+     * This method here print the contents (the intervals) as well.
+     *
+     * @param writer
+     *            The PrintWriter to which the debug info will be written
+     * @param printIntervals
+     *            Should we also print every contained interval individually?
+     * @param ts
+     *            The timestamp that nodes have to intersect for intervals to be
+     *            printed. A negative value will print intervals for all nodes.
+     *            The timestamp only applies if printIntervals is true.
+     */
+    public void debugPrint(PrintWriter writer, boolean printIntervals, long ts) {
+        /* Only used for debugging, shouldn't be externalized */
+        writer.println("------------------------------"); //$NON-NLS-1$
+        writer.println("State History Tree:\n"); //$NON-NLS-1$
+        writer.println(getSHT().toString());
+        writer.println("Average node utilization: " //$NON-NLS-1$
+                + getAverageNodeUsage());
+        writer.println(""); //$NON-NLS-1$
+
+        getHistoryTree().debugPrintFullTree(writer, printIntervals, ts);
+    }
 }
index b46894d47819559ce90702ba1513b8f93a77e9f8..d6675c59bf0e2599ca372c23821862fc29fa0748 100644 (file)
@@ -16,6 +16,7 @@ import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.nio.channels.ClosedChannelException;
 import java.util.List;
 
@@ -71,8 +72,13 @@ public class HistoryTreeClassicStub extends HistoryTreeClassic {
         super(existingStateFile, expProviderVersion);
     }
 
+    // ------------------------------------------------------------------------
+    // Extra test accessors
+    // ------------------------------------------------------------------------
+
     @Override
     public List<HTNode> getLatestBranch() {
+        /* Super method is not public */
         return checkNotNull(super.getLatestBranch());
     }
 
@@ -108,6 +114,118 @@ public class HistoryTreeClassicStub extends HistoryTreeClassic {
         return getLatestBranch().size();
     }
 
+    // ------------------------------------------------------------------------
+    // Debug printing methods
+    // ------------------------------------------------------------------------
+
+    /**
+     * Print out the full tree for debugging purposes
+     *
+     * @param writer
+     *            PrintWriter in which to write the output
+     * @param printIntervals
+     *            Flag to enable full output of the interval information
+     * @param ts
+     *            The timestamp that nodes have to intersect for intervals to be
+     *            printed. A negative value will print intervals for all nodes.
+     *            The timestamp only applies if printIntervals is true.
+     */
+    public void debugPrintFullTree(PrintWriter writer, boolean printIntervals, long ts) {
+        preOrderPrint(writer, false, getLatestBranch().get(0), 0, ts);
+
+        if (printIntervals) {
+            preOrderPrint(writer, true, getLatestBranch().get(0), 0, ts);
+        }
+        writer.println('\n');
+    }
+
+    /**
+     * Start at currentNode and print the contents of all its children, in
+     * pre-order. Give the root node in parameter to visit the whole tree, and
+     * have a nice overview.
+     */
+    private void preOrderPrint(PrintWriter writer, boolean printIntervals,
+            HTNode currentNode, int curDepth, long ts) {
+
+        writer.println(currentNode.toString());
+        /*
+         * Print intervals only if timestamp is negative or within the range of
+         * the node
+         */
+        if (printIntervals &&
+                (ts <= 0 ||
+                        (ts >= currentNode.getNodeStart() && ts <= currentNode.getNodeEnd()))) {
+            currentNode.debugPrintIntervals(writer);
+        }
+
+        switch (currentNode.getNodeType()) {
+        case LEAF:
+            /* Stop if it's the leaf node */
+            return;
+
+        case CORE:
+            try {
+                final CoreNode node = (CoreNode) currentNode;
+                /* Print the extensions, if any */
+                int extension = node.getExtensionSequenceNumber();
+                while (extension != -1) {
+                    HTNode nextNode = getTreeIO().readNode(extension);
+                    preOrderPrint(writer, printIntervals, nextNode, curDepth, ts);
+                }
+
+                /* Print the child nodes */
+                for (int i = 0; i < node.getNbChildren(); i++) {
+                    HTNode nextNode = getTreeIO().readNode(node.getChild(i));
+                    for (int j = 0; j < curDepth; j++) {
+                        writer.print("  ");
+                    }
+                    writer.print("+-");
+                    preOrderPrint(writer, printIntervals, nextNode, curDepth + 1, ts);
+                }
+            } catch (ClosedChannelException e) {
+            }
+            break;
+
+        default:
+            break;
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Assertion methods, for use with JUnit tests
+    // ------------------------------------------------------------------------
+
+    /**
+     * Check the integrity of all the nodes in the tree. Calls
+     * {@link #assertNodeIntegrity} for every node in the tree.
+     */
+    public void assertIntegrity() {
+        try {
+            for (int i = 0; i < getNodeCount(); i++) {
+                assertNodeIntegrity(getNode(i));
+            }
+        } catch (ClosedChannelException e) {
+            fail(e.getMessage());
+        }
+    }
+
+    /**
+     * Debugging method to make sure all intervals contained in the given node
+     * have valid start and end times.
+     *
+     * @param node
+     *            The node to check
+     */
+    private void assertNodeIntegrity(HTNode node) {
+        if (node instanceof CoreNode) {
+            assertChildrenIntegrity((CoreNode) node);
+        }
+
+        /* Check that all intervals are within the node's range */
+        // TODO: Get the intervals of a node
+
+    }
+
     private void assertChildrenIntegrity(CoreNode node) {
         try {
             /*
@@ -148,35 +266,4 @@ public class HistoryTreeClassicStub extends HistoryTreeClassic {
         }
     }
 
-    /**
-     * Debugging method to make sure all intervals contained in the given node
-     * have valid start and end times.
-     *
-     * @param node
-     *            The node to check
-     */
-    private void assertNodeIntegrity(HTNode node) {
-        if (node instanceof CoreNode) {
-            assertChildrenIntegrity((CoreNode) node);
-        }
-
-        /* Check that all intervals are within the node's range */
-        // TODO: Get the intervals of a node
-
-    }
-
-    /**
-     * Check the integrity of all the nodes in the tree. Calls
-     * {@link #assertNodeIntegrity} for every node in the tree.
-     */
-    public void assertIntegrity() {
-        try {
-            for (int i = 0; i < getNodeCount(); i++) {
-                assertNodeIntegrity(getNode(i));
-            }
-        } catch (ClosedChannelException e) {
-            fail(e.getMessage());
-        }
-    }
-
 }
diff --git a/statesystem/org.eclipse.tracecompass.statesystem.core/.settings/.api_filters b/statesystem/org.eclipse.tracecompass.statesystem.core/.settings/.api_filters
new file mode 100644 (file)
index 0000000..7943278
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<component id="org.eclipse.tracecompass.statesystem.core" version="2">
+    <resource path="src/org/eclipse/tracecompass/statesystem/core/backend/IStateHistoryBackend.java" type="org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend">
+        <filter comment="Removed debugPrint() method which was only used for testing" id="405901410">
+            <message_arguments>
+                <message_argument value="org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend"/>
+                <message_argument value="debugPrint(PrintWriter)"/>
+            </message_arguments>
+        </filter>
+    </resource>
+</component>
index 3f8a6425bc0335b77c6ba62597ebcb59200596f4..eabedb5bce7920e5a816ff97bf87a61c1a0eee20 100644 (file)
@@ -17,7 +17,6 @@ package org.eclipse.tracecompass.internal.statesystem.core;
 
 import java.io.File;
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.LinkedList;
@@ -612,17 +611,4 @@ public class StateSystem implements ITmfStateSystemBuilder {
                 attribute + " at time " + timestamp + //$NON-NLS-1$
                 ", returning dummy interval"); //$NON-NLS-1$
     }
-
-    /**
-     * Print out the contents of the inner structures.
-     *
-     * @param writer
-     *            The PrintWriter in which to print the output
-     */
-    public void debugPrint(@NonNull PrintWriter writer) {
-        getAttributeTree().debugPrint(writer);
-        transState.debugPrint(writer);
-        backend.debugPrint(writer);
-    }
-
 }
index 40e86b027a127fcb85b04f210ee7bde8d1875d3f..e5505c3ea58546ca23876370bc0eb8a2e4ba3dbc 100644 (file)
@@ -16,7 +16,6 @@ package org.eclipse.tracecompass.internal.statesystem.core.backend;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.PrintWriter;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
@@ -224,13 +223,6 @@ public class InMemoryBackend implements IStateHistoryBackend {
         /* Nothing to do */
     }
 
-    @Override
-    public void debugPrint(PrintWriter writer) {
-        synchronized (intervals) {
-            writer.println(intervals.toString());
-        }
-    }
-
     private static Iterator<ITmfStateInterval> searchforEndTime(NavigableSet<ITmfStateInterval> tree, long time) {
         ITmfStateInterval dummyInterval = new TmfStateInterval(-1, time, -1, TmfStateValue.nullValue());
         ITmfStateInterval myInterval = tree.lower(dummyInterval);
index c373b123102faecdb2497d7d5bbb48794b6aba59..33a0781d732f29cb41df25bd459fc68ad41d6f43 100644 (file)
@@ -14,7 +14,6 @@ package org.eclipse.tracecompass.internal.statesystem.core.backend;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.PrintWriter;
 import java.util.List;
 
 import org.eclipse.jdt.annotation.NonNull;
@@ -117,9 +116,4 @@ public class NullBackend implements IStateHistoryBackend {
         /* Cannot do past queries */
         return null;
     }
-
-    @Override
-    public void debugPrint(PrintWriter writer) {
-        writer.println("Null history backend"); //$NON-NLS-1$
-    }
 }
index c69c51b6e18e97f63f71f39f957021cce83d9a43..25f7281518cc530592a8614beb2240ec20b50066 100644 (file)
@@ -45,7 +45,7 @@ import com.google.common.cache.LoadingCache;
  *
  * @author Alexandre Montplaisir
  */
-class HT_IO {
+public class HT_IO {
 
     private static final Logger LOGGER = TraceCompassLog.getLogger(HT_IO.class);
 
@@ -198,6 +198,12 @@ class HT_IO {
         }
     }
 
+    /**
+     * Write the given node to disk.
+     *
+     * @param node
+     *            The node to write.
+     */
     public void writeNode(HTNode node) {
         try {
             int seqNumber = node.getSequenceNumber();
@@ -217,10 +223,23 @@ class HT_IO {
         }
     }
 
+    /**
+     * Get the output file channel, used for writing.
+     *
+     * @return The output file channel
+     */
     public FileChannel getFcOut() {
         return fFileChannelOut;
     }
 
+    /**
+     * Retrieve the input stream with which to write the attribute tree.
+     *
+     * @param nodeOffset
+     *            The offset in the file, in number of nodes. This should be
+     *            after all the nodes.
+     * @return The correctly-seeked input stream
+     */
     public FileInputStream supplyATReader(int nodeOffset) {
         try {
             /*
@@ -234,6 +253,9 @@ class HT_IO {
         return fFileInputStream;
     }
 
+    /**
+     * Close all file channels and streams.
+     */
     public synchronized void closeFile() {
         try {
             fFileInputStream.close();
@@ -243,6 +265,9 @@ class HT_IO {
         }
     }
 
+    /**
+     * Delete the history tree file
+     */
     public synchronized void deleteFile() {
         closeFile();
 
index 344c3b0f11c7cce3d034f2973a9d2195d555c0d1..188c9da8be29dafaefc7492d592b66dafef5781e 100644 (file)
@@ -18,7 +18,6 @@ package org.eclipse.tracecompass.internal.statesystem.core.backend.historytree;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.nio.channels.ClosedChannelException;
 import java.util.List;
 
@@ -363,36 +362,4 @@ public class HistoryTreeBackend implements IStateHistoryBackend {
         return (int) ret;
     }
 
-    @Override
-    public void debugPrint(PrintWriter writer) {
-        /* By default don't print out all the intervals */
-        debugPrint(writer, false, -1);
-    }
-
-    /**
-     * The basic debugPrint method will print the tree structure, but not their
-     * contents.
-     *
-     * This method here print the contents (the intervals) as well.
-     *
-     * @param writer
-     *            The PrintWriter to which the debug info will be written
-     * @param printIntervals
-     *            Should we also print every contained interval individually?
-     * @param ts
-     *            The timestamp that nodes have to intersect for intervals to be
-     *            printed. A negative value will print intervals for all nodes.
-     *            The timestamp only applies if printIntervals is true.
-     */
-    public void debugPrint(PrintWriter writer, boolean printIntervals, long ts) {
-        /* Only used for debugging, shouldn't be externalized */
-        writer.println("------------------------------"); //$NON-NLS-1$
-        writer.println("State History Tree:\n"); //$NON-NLS-1$
-        writer.println(getSHT().toString());
-        writer.println("Average node utilization: " //$NON-NLS-1$
-                + getAverageNodeUsage());
-        writer.println(""); //$NON-NLS-1$
-
-        getSHT().debugPrintFullTree(writer, printIntervals, ts);
-    }
 }
index 8bf229dccd21cefd2a22bcbc006e3eb3e04f00ef..54b8793543aa4e9fe78254e33ec4851b135b8bb8 100644 (file)
@@ -17,7 +17,6 @@ package org.eclipse.tracecompass.internal.statesystem.core.backend.historytree;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 import java.nio.channels.ClosedChannelException;
@@ -27,7 +26,6 @@ import java.util.Collections;
 import java.util.List;
 
 import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.internal.statesystem.core.Activator;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
 import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
 
@@ -59,7 +57,7 @@ public class HistoryTreeClassic implements IHistoryTree {
     private final HTConfig fConfig;
 
     /** Reader/writer object */
-    private final HT_IO fTreeIO;
+    private final @NonNull HT_IO fTreeIO;
 
     // ------------------------------------------------------------------------
     // Variable Fields (will change throughout the existence of the SHT)
@@ -343,6 +341,16 @@ public class HistoryTreeClassic implements IHistoryTree {
         return fTreeIO.readNode(seqNum);
     }
 
+    /**
+     * Retrieve the TreeIO object. Should only be used for testing.
+     *
+     * @return The TreeIO
+     */
+    @VisibleForTesting
+    protected @NonNull HT_IO getTreeIO() {
+        return fTreeIO;
+    }
+
     // ------------------------------------------------------------------------
     // HT_IO interface
     // ------------------------------------------------------------------------
@@ -636,68 +644,4 @@ public class HistoryTreeClassic implements IHistoryTree {
                 + fLatestBranch.get(fLatestBranch.size() - 1).getSequenceNumber();
     }
 
-    /**
-     * Start at currentNode and print the contents of all its children, in
-     * pre-order. Give the root node in parameter to visit the whole tree, and
-     * have a nice overview.
-     */
-    /* Only used for debugging, shouldn't be externalized */
-    @SuppressWarnings("nls")
-    private void preOrderPrint(PrintWriter writer, boolean printIntervals,
-            HTNode currentNode, int curDepth, long ts) {
-
-        writer.println(currentNode.toString());
-        /* Print intervals only if timestamp is negative or within the range of the node */
-        if (printIntervals &&
-                (ts <= 0 ||
-                (ts >= currentNode.getNodeStart() && ts <= currentNode.getNodeEnd()))) {
-            currentNode.debugPrintIntervals(writer);
-        }
-
-        switch (currentNode.getNodeType()) {
-        case LEAF:
-            /* Stop if it's the leaf node */
-            return;
-
-        case CORE:
-            try {
-                final CoreNode node = (CoreNode) currentNode;
-                /* Print the extensions, if any */
-                int extension = node.getExtensionSequenceNumber();
-                while (extension != -1) {
-                    HTNode nextNode = fTreeIO.readNode(extension);
-                    preOrderPrint(writer, printIntervals, nextNode, curDepth, ts);
-                }
-
-                /* Print the child nodes */
-                for (int i = 0; i < node.getNbChildren(); i++) {
-                    HTNode nextNode = fTreeIO.readNode(node.getChild(i));
-                    for (int j = 0; j < curDepth; j++) {
-                        writer.print("  ");
-                    }
-                    writer.print("+-");
-                    preOrderPrint(writer, printIntervals, nextNode, curDepth + 1, ts);
-                }
-            } catch (ClosedChannelException e) {
-                Activator.getDefault().logError(e.getMessage());
-            }
-            break;
-
-        default:
-            break;
-        }
-    }
-
-    @Override
-    public void debugPrintFullTree(PrintWriter writer, boolean printIntervals, long ts) {
-        /* Only used for debugging, shouldn't be externalized */
-
-        preOrderPrint(writer, false, fLatestBranch.get(0), 0, ts);
-
-        if (printIntervals) {
-            preOrderPrint(writer, true, fLatestBranch.get(0), 0, ts);
-        }
-        writer.println('\n');
-    }
-
 }
index f58d9ae9125d17ca16fcf941bb91a1a6f21eb9aa..46263744d9eca6c110563d59fd770e9abc6d11f2 100644 (file)
@@ -11,7 +11,6 @@ package org.eclipse.tracecompass.internal.statesystem.core.backend.historytree;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.PrintWriter;
 import java.nio.channels.ClosedChannelException;
 
 import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
@@ -167,18 +166,4 @@ public interface IHistoryTree {
      */
     long getFileSize();
 
-    /**
-     * Print out the full tree for debugging purposes
-     *
-     * @param writer
-     *            PrintWriter in which to write the output
-     * @param printIntervals
-     *            Flag to enable full output of the interval information
-     * @param ts
-     *            The timestamp that nodes have to intersect for intervals to be
-     *            printed. A negative value will print intervals for all nodes.
-     *            The timestamp only applies if printIntervals is true.
-     */
-    void debugPrintFullTree(PrintWriter writer, boolean printIntervals, long ts);
-
 }
index 6e71574be6d05147a156fb8579c5a88ef74d36ea..b36aa86ab540951a2bd49950eea91e4cc088c1a3 100644 (file)
@@ -14,7 +14,6 @@ package org.eclipse.tracecompass.statesystem.core.backend;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.PrintWriter;
 import java.util.List;
 
 import org.eclipse.jdt.annotation.NonNull;
@@ -182,11 +181,4 @@ public interface IStateHistoryBackend {
     ITmfStateInterval doSingularQuery(long t, int attributeQuark)
             throws TimeRangeException, StateSystemDisposedException;
 
-    /**
-     * Debug method to print the contents of the history backend.
-     *
-     * @param writer
-     *            The PrintWriter where to write the output
-     */
-    void debugPrint(PrintWriter writer);
 }
index 89414feeff5f7166443301ef376342cc16daed96..4ed0ba10ed3c8e767656aeb75be7f38651faace2 100644 (file)
@@ -17,7 +17,6 @@ import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNullCont
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.PrintWriter;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
@@ -279,11 +278,6 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
         return (t >= getStartTime() && t <= getEndTime());
     }
 
-    @Override
-    public void debugPrint(PrintWriter writer) {
-        // TODO Auto-generated method stub
-    }
-
     private void waitForCheckpoints() {
         try {
             fCheckpointsReady.await();
This page took 0.05099 seconds and 5 git commands to generate.