• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

knowledgepixels / nanopub-registry / 30893238389

04 Aug 2026 08:44AM UTC coverage: 83.415% (+51.1%) from 32.285%
30893238389

Pull #123

github

web-flow
Merge 84fad06c1 into e5ed6d462
Pull Request #123: Add unit tests for existing functionality

865 of 1112 branches covered (77.79%)

Branch coverage included in aggregate %.

2706 of 3169 relevant lines covered (85.39%)

12.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.92
src/main/java/com/knowledgepixels/registry/DebugPage.java
1
package com.knowledgepixels.registry;
2

3
import com.mongodb.client.ClientSession;
4
import com.mongodb.client.MongoCursor;
5
import io.vertx.ext.web.RoutingContext;
6
import org.bson.Document;
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9

10
import java.io.IOException;
11

12
import static com.knowledgepixels.registry.RegistryDB.collection;
13
import static com.mongodb.client.model.Indexes.ascending;
14

15
public class DebugPage extends Page {
16

17
    private static final Logger logger = LoggerFactory.getLogger(DebugPage.class);
12✔
18

19
    public static void show(RoutingContext context) {
20
        DebugPage page;
21
        logger.info("Received debug request: {}", context.request().path());
18✔
22
        try (ClientSession s = RegistryDB.getClient().startSession()) {
9✔
23
            s.startTransaction();
6✔
24
            page = new DebugPage(s, context);
18✔
25
            page.show();
6✔
26
        } catch (IOException ex) {
×
27
            logger.warn("Failed to show debug page for request {}: {} ({})", context.request().path(), ex.getMessage(), ex.getClass().getSimpleName(), ex);
×
28
        } finally {
29
            logger.debug("Ending response for debug request: {}", context.request().path());
18✔
30
            context.response().end();
12✔
31
            // TODO Clean-up here?
32
        }
33
    }
3✔
34

35
    private DebugPage(ClientSession mongoSession, RoutingContext context) {
36
        super(mongoSession, context);
12✔
37
    }
3✔
38

39
    protected void show() throws IOException {
40
        RoutingContext c = getContext();
9✔
41
        logger.debug("Preparing debug response for {}", getFullRequest());
15✔
42

43
        if (getRequestString().matches("/debug/trustPaths")) {
15✔
44
            String counterString = c.request().getParam("trustStateCounter");
15✔
45
            if (counterString == null) {
6✔
46
                logger.info("Serving current trustPaths for {}", getFullRequest());
15✔
47
                print(getTrustPathsTxt(mongoSession));
18✔
48
            } else {
49
                Long counter = Long.parseLong(counterString);
12✔
50
                logger.info("Serving trustPaths for trustStateCounter={} request={}", counter, getFullRequest());
18✔
51
                print(RegistryDB.getOne(mongoSession, "debug_trustPaths", new Document("trustStateCounter", counter)).getString("trustStateTxt"));
39✔
52
            }
53
            setRespContentType("text/plain");
9✔
54
        } else if (getRequestString().matches("/debug/endorsements")) {
18✔
55
            int count;
56
            try (MongoCursor<Document> tp = collection("endorsements").find(mongoSession).cursor()) {
21✔
57
                count = 0;
6✔
58
                while (tp.hasNext()) {
9✔
59
                    Document d = tp.next();
12✔
60
                    println(d.get("agent") + ">" + d.get("pubkey") + " " + d.get("endorsedNanopub") + " " + d.get("source") + " (" + d.get("status") + ")");
69✔
61
                    count++;
3✔
62
                }
3✔
63
            }
64
            setRespContentType("text/plain");
9✔
65
            logger.info("Listed {} endorsements for {}", count, getFullRequest());
21✔
66
        } else if (getRequestString().matches("/debug/accounts")) {
18✔
67
            int count;
68
            try (MongoCursor<Document> tp = collection("accounts").find(mongoSession).cursor()) {
21✔
69
                count = 0;
6✔
70
                while (tp.hasNext()) {
9✔
71
                    Document d = tp.next();
12✔
72
                    println(d.getString("agent") + ">" + d.get("pubkey") + " " + d.get("depth") + " (" + d.get("status") + ")");
54✔
73
                    count++;
3✔
74
                }
3✔
75
            }
76
            logger.info("Listed {} accounts for {}", count, getFullRequest());
21✔
77
        } else if (getRequestString().matches("/debug/tasks")) {
18✔
78
            setRespContentType("text/plain");
9✔
79
            try {
80
                String currentTask = Task.getCurrentTaskName();
6✔
81
                if (currentTask != null) {
6!
82
                    long elapsed = System.currentTimeMillis() - Task.getCurrentTaskStartTime();
×
83
                    println("Currently running: " + currentTask + " (for " + elapsed + "ms)");
×
84
                } else {
×
85
                    println("Currently running: (none)");
9✔
86
                }
87
                println("");
9✔
88
                int count;
89
                try (MongoCursor<Document> tasks = collection(Collection.TASKS.toString()).find(mongoSession)
36✔
90
                        .sort(ascending("not-before")).cursor()) {
12✔
91
                    count = 0;
6✔
92
                    while (tasks.hasNext()) {
9✔
93
                        println(tasks.next().toJson());
18✔
94
                        count++;
6✔
95
                    }
96
                }
97
                println("Total queued tasks: " + count);
12✔
98
                logger.info("Listed {} queued tasks for {}", count, getFullRequest());
21✔
99
            } catch (Exception ex) {
3✔
100
                logger.warn("Failed while listing tasks for {}: {} ({})", getFullRequest(), ex.getMessage(), ex.getClass().getSimpleName(), ex);
75✔
101
                println("Error: " + ex.getClass().getName() + ": " + ex.getMessage());
24✔
102
            }
6✔
103
        } else if (getRequestString().matches("/debug/peerState")) {
15✔
104
            setRespContentType("text/plain");
9✔
105
            try {
106
                long count = collection(Collection.PEER_STATE.toString()).countDocuments(mongoSession);
21✔
107
                println("peerState documents: " + count);
12✔
108
                int listed;
109
                try (MongoCursor<Document> ps = collection(Collection.PEER_STATE.toString()).find(mongoSession).cursor()) {
24✔
110
                    listed = 0;
6✔
111
                    while (ps.hasNext()) {
9✔
112
                        println(ps.next().toJson());
18✔
113
                        listed++;
6✔
114
                    }
115
                }
116
                logger.info("Listed {} peerState documents for {}", listed, getFullRequest());
21✔
117
            } catch (Exception ex) {
3✔
118
                logger.warn("Failed while listing peerState for {}: {} ({})", getFullRequest(), ex.getMessage(), ex.getClass().getSimpleName(), ex);
75✔
119
                println("Error: " + ex.getClass().getName() + ": " + ex.getMessage());
24✔
120
            }
6✔
121
        } else {
122
            logger.warn("Invalid debug request path: {}", getFullRequest());
15✔
123
            c.response().setStatusCode(400).setStatusMessage("Invalid request: " + getFullRequest());
27✔
124
        }
125
    }
3✔
126

127
    public static String getTrustPathsTxt(ClientSession mongoSession) {
128
        String s = "";
6✔
129
        try (MongoCursor<Document> tp = collection("trustPaths").find(mongoSession).sort(ascending("_id")).cursor()) {
42✔
130
            while (tp.hasNext()) {
9✔
131
                Document d = tp.next();
12✔
132
                String path = d.getString("_id");
12✔
133
                path = path.replace(" ", " > ");
15✔
134
                if (d.getString("type").equals("extended")) {
18✔
135
                    path = path.replaceFirst(" > ([^ ]+)$", " ~ $1");
15✔
136
                }
137
                s += path + "\n";
12✔
138
            }
3✔
139
        }
140
        return s;
6✔
141
    }
142

143
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc