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

leeonky / test-charm-java / 212

14 Apr 2025 05:15AM UTC coverage: 74.088% (-0.1%) from 74.209%
212

push

circleci

leeonky
Update version

7957 of 10740 relevant lines covered (74.09%)

0.74 hits per line

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

91.36
/DAL-java/src/main/java/com/github/leeonky/dal/runtime/inspector/DumpingBuffer.java
1
package com.github.leeonky.dal.runtime.inspector;
2

3
import com.github.leeonky.dal.runtime.Data;
4
import com.github.leeonky.dal.runtime.RuntimeContextBuilder.DALRuntimeContext;
5

6
import java.util.HashMap;
7
import java.util.Map;
8
import java.util.concurrent.atomic.AtomicInteger;
9
import java.util.function.Consumer;
10

11
import static com.github.leeonky.dal.runtime.DalException.extractException;
12
import static java.lang.String.format;
13
import static java.util.Collections.nCopies;
14

15
public class DumpingBuffer {
16
    private final String path;
17
    private final int indent;
18
    private final LineBuffer lineBuffer;
19
    private StringBuilder splits;
20
    private int length = 0;
1✔
21
    private final DALRuntimeContext runtimeContext;
22
    private final AtomicInteger dumpedObjectCount;
23

24
    private DumpingBuffer(String path, int indent, StringBuilder splits, LineBuffer buffer, DALRuntimeContext context, AtomicInteger dumpedObjectCount) {
1✔
25
        this.path = path;
1✔
26
        lineBuffer = buffer;
1✔
27
        runtimeContext = context;
1✔
28
        this.indent = indent;
1✔
29
        this.splits = splits;
1✔
30
        this.dumpedObjectCount = dumpedObjectCount;
1✔
31
    }
1✔
32

33
    public static DumpingBuffer rootContext(DALRuntimeContext context) {
34
        return new DumpingBuffer("root", 0, new StringBuilder(), new LineBuffer(context), context, new AtomicInteger(0));
1✔
35
    }
36

37
    public String getPath() {
38
        return path;
×
39
    }
40

41
    public DALRuntimeContext getRuntimeContext() {
42
        return runtimeContext;
×
43
    }
44

45
    private void checkCount() {
46
        if (dumpedObjectCount.getAndIncrement() == runtimeContext.maxDumpingObjectSize())
1✔
47
            throw new MaximizeDump();
×
48
    }
1✔
49

50
    public DumpingBuffer dump(Data data) {
51
        checkCount();
1✔
52
        try {
53
            runtimeContext.fetchDumper(data).dump(data, this);
1✔
54
        } catch (Throwable e) {
1✔
55
            append(e);
1✔
56
        }
1✔
57
        return this;
1✔
58
    }
59

60
    public DumpingBuffer dumpValue(Data data) {
61
        checkCount();
1✔
62
        try {
63
            runtimeContext.fetchDumper(data).dumpValue(data, this);
1✔
64
        } catch (Throwable e) {
1✔
65
            append(e);
1✔
66
        }
1✔
67
        return this;
1✔
68
    }
69

70
    public DumpingBuffer index(int index) {
71
        return createSub(format("%s[%d]", path, index), 0);
1✔
72
    }
73

74
    public DumpingBuffer sub(Object property) {
75
        return createSub(format("%s.%s", path, property), 0);
1✔
76
    }
77

78
    public DumpingBuffer indent() {
79
        return createSub(path, 1);
1✔
80
    }
81

82
    public DumpingBuffer indent(Consumer<DumpingBuffer> subDump) {
83
        DumpingBuffer sub = indent();
1✔
84
        try {
85
            subDump.accept(sub);
1✔
86
        } catch (MaximizeDump ignore) {
×
87
            sub.newLine().append("*... Too many objects!*");
×
88
        }
1✔
89
        return this;
1✔
90
    }
91

92
    public DumpingBuffer sub() {
93
        return createSub(path, 0);
×
94
    }
95

96
    private DumpingBuffer createSub(String subPath, int indent) {
97
        return new DumpingBuffer(subPath, this.indent + indent, takeSplits(), lineBuffer, runtimeContext,
1✔
98
                indent == 0 ? dumpedObjectCount : new AtomicInteger(0));
99
    }
100

101
    private StringBuilder takeSplits() {
102
        StringBuilder temp = splits;
1✔
103
        splits = new StringBuilder();
1✔
104
        return temp;
1✔
105
    }
106

107
    public void cached(Data data, Runnable runnable) {
108
        lineBuffer.cached(path, data, runnable, p -> append("*reference* " + p));
1✔
109
    }
1✔
110

111
    public DumpingBuffer append(String s) {
112
        length = lineBuffer.append(takeSplits(), s).length();
1✔
113
        return this;
1✔
114
    }
115

116
    public DumpingBuffer append(Throwable e) {
117
        return append("*throw* " + extractException(e).orElse(e));
1✔
118
    }
119

120
    public String content() {
121
        return lineBuffer.toString();
1✔
122
    }
123

124
    public DumpingBuffer appendThen(String then) {
125
        splits.append(then);
1✔
126
        return this;
1✔
127
    }
128

129
    public DumpingBuffer newLine() {
130
        appendThen("\n" + String.join("", nCopies(indent, "    ")));
1✔
131
        return this;
1✔
132
    }
133

134
    public DumpingBuffer optionalNewLine() {
135
        if (length != lineBuffer.length())
1✔
136
            newLine();
1✔
137
        return this;
1✔
138
    }
139

140
    public static class LineBuffer {
141
        private final Map<DumpingCacheKey, String> caches = new HashMap<>();
1✔
142
        private final DALRuntimeContext runtimeContext;
143
        private final StringBuilder stringBuilder = new StringBuilder();
1✔
144
        private int lineCount = 0;
1✔
145
        private boolean finished = false;
1✔
146

147
        public LineBuffer(DALRuntimeContext runtimeContext) {
1✔
148
            this.runtimeContext = runtimeContext;
1✔
149
        }
1✔
150

151
        public void cached(String path, Data data, Runnable dumpAction, Consumer<String> refAction) {
152
            DumpingCacheKey key = new DumpingCacheKey(data);
1✔
153
            String reference = caches.get(key);
1✔
154
            if (reference == null) {
1✔
155
                caches.put(key, path);
1✔
156
                dumpAction.run();
1✔
157
            } else {
158
                refAction.accept(reference);
1✔
159
            }
160
        }
1✔
161

162
        public int length() {
163
            return stringBuilder.length();
1✔
164
        }
165

166
        @Override
167
        public String toString() {
168
            return stringBuilder.toString();
1✔
169
        }
170

171
        public LineBuffer append(StringBuilder splits, String content) {
172
            if (!finished) {
1✔
173
                if (splits.length() != 0) {
1✔
174
                    if ((lineCount += splits.chars().filter(c -> c == '\n').count())
1✔
175
                            >= runtimeContext.maxDumpingLineCount()) {
1✔
176
                        stringBuilder.append("\n...");
1✔
177
                        finished = true;
1✔
178
                        return this;
1✔
179
                    }
180
                    stringBuilder.append(splits);
1✔
181
                }
182
                stringBuilder.append(content);
1✔
183
            }
184
            return this;
1✔
185
        }
186
    }
187

188
    public static class MaximizeDump extends RuntimeException {
×
189
    }
190
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc