Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-157-debug f3286d18d -> d43074e70


# ignite-157-debug


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/d43074e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/d43074e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/d43074e7

Branch: refs/heads/ignite-157-debug
Commit: d43074e705e0ff4ac63baf356af0397aaf44d0d0
Parents: f3286d1
Author: sboikov <sboi...@gridgain.com>
Authored: Tue Apr 28 10:10:47 2015 +0300
Committer: sboikov <sboi...@gridgain.com>
Committed: Tue Apr 28 10:10:47 2015 +0300

----------------------------------------------------------------------
 .../internal/processors/cache/TestDebugLog.java | 204 +++++++++++++++++++
 1 file changed, 204 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d43074e7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/TestDebugLog.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/TestDebugLog.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/TestDebugLog.java
new file mode 100644
index 0000000..203a992
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/TestDebugLog.java
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import org.apache.ignite.internal.util.typedef.internal.*;
+
+import java.io.*;
+import java.text.*;
+import java.util.*;
+
+/**
+ * TODO
+ */
+public class TestDebugLog {
+    /** */
+    private static final List<Object> msgs = Collections.synchronizedList(new 
ArrayList<>(100_000));
+
+    /** */
+    private static final SimpleDateFormat DEBUG_DATE_FMT = new 
SimpleDateFormat("HH:mm:ss,SSS");
+
+    static class Message {
+        String thread = Thread.currentThread().getName();
+
+        String msg;
+
+        long ts = U.currentTimeMillis();
+
+        public Message(String msg) {
+            this.msg = msg;
+        }
+
+        public String toString() {
+            return "Msg [msg=" + msg + ", thread=" + thread + ", time=" + 
DEBUG_DATE_FMT.format(new Date(ts)) + ']';
+        }
+    }
+
+    static class EntryMessage extends Message {
+        Object key;
+        Object val;
+
+        public EntryMessage(Object key, Object val, String msg) {
+            super(msg);
+
+            this.key = key;
+            this.val = val;
+        }
+
+        public String toString() {
+            return "EntryMsg [key=" + key + ", msg=" + msg + ", thread=" + 
thread + ", time=" + DEBUG_DATE_FMT.format(new Date(ts)) + ", val=" + val + ']';
+        }
+    }
+
+    static class PartitionMessage extends Message {
+        int part;
+
+        public PartitionMessage(int part, String msg) {
+            super(msg);
+
+            this.part = part;
+        }
+
+        public String toString() {
+            return "PartMsg [part=" + part + ", msg=" + msg + ", thread=" + 
thread + ", time=" + DEBUG_DATE_FMT.format(new Date(ts)) + ']';
+        }
+    }
+
+    static final boolean out = false;
+
+    public static void addMessage(String msg) {
+        msgs.add(new Message(msg));
+
+        if (out)
+            System.out.println(msg);
+    }
+
+    public static void addEntryMessage(Object key, Object val, String msg) {
+        assert key != null;
+
+        EntryMessage msg0 = new EntryMessage(key, val, msg);
+
+        msgs.add(msg0);
+
+        if (out)
+            System.out.println(msg0.toString());
+    }
+
+    public static void addPartMessage(int part, String msg) {
+        PartitionMessage msg0 = new PartitionMessage(part, msg);
+
+        msgs.add(msg0);
+
+        if (out)
+            System.out.println(msg0.toString());
+    }
+
+    public static void printMessages(boolean file) {
+        List<Object> msgs0;
+
+        synchronized (msgs) {
+            msgs0 = new ArrayList<>(msgs);
+
+            msgs.clear();
+        }
+
+        if (file) {
+            try {
+                FileOutputStream out = new FileOutputStream("test_debug.log");
+
+                PrintWriter w = new PrintWriter(out);
+
+                for (Object msg : msgs0)
+                    w.println(msg.toString());
+
+                w.close();
+
+                out.close();
+            }
+            catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        else {
+            for (Object msg : msgs0)
+                System.out.println(msg);
+        }
+    }
+
+    public static void printKeyMessages(String fileName, Object key) {
+        assert key != null;
+
+        printKeyMessages(fileName, key, null);
+    }
+
+    public static void printKeyMessages(String fileName, Object key, Integer 
part) {
+        List<Object> msgs0;
+
+        synchronized (msgs) {
+            msgs0 = new ArrayList<>(msgs);
+
+            msgs.clear();
+        }
+
+        if (fileName != null) {
+            try {
+                FileOutputStream out = new FileOutputStream(fileName);
+
+                PrintWriter w = new PrintWriter(out);
+
+                for (Object msg : msgs0) {
+                    if (msg instanceof EntryMessage && 
!((EntryMessage)msg).key.equals(key))
+                        continue;
+
+                    if (part != null) {
+                        if (msg instanceof PartitionMessage) {
+                            PartitionMessage partMsg = (PartitionMessage)msg;
+
+                            if (partMsg.part != part.intValue())
+                                continue;
+                        }
+                    }
+
+                    w.println(msg.toString());
+                }
+
+                w.close();
+
+                out.close();
+            }
+            catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        else {
+            for (Object msg : msgs0) {
+                if (msg instanceof EntryMessage && 
!((EntryMessage)msg).key.equals(key))
+                    continue;
+
+                System.out.println(msg);
+            }
+        }
+    }
+
+    public static void clear() {
+        msgs.clear();
+    }
+
+    public static void main(String[] args) {
+    }
+}

Reply via email to