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

leeonky / test-charm-java / 156

20 Mar 2025 01:53PM UTC coverage: 74.243% (-0.2%) from 74.475%
156

push

circleci

leeonky
Refactor

14 of 15 new or added lines in 12 files covered. (93.33%)

126 existing lines in 29 files now uncovered.

7947 of 10704 relevant lines covered (74.24%)

0.74 hits per line

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

91.57
/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.Data.Resolved;
5
import com.github.leeonky.dal.runtime.RuntimeContextBuilder.DALRuntimeContext;
6

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

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

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

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

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

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

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

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

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

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

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

77
    public DumpingBuffer sub(Object property) {
78
        return createSub(format("%s.%s", path, property), 0);
1✔
79
    }
80

81
    public DumpingBuffer indent() {
82
        return createSub(path, 1);
1✔
83
    }
84

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

95
    public DumpingBuffer sub() {
UNCOV
96
        return createSub(path, 0);
×
97
    }
98

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

104
    private StringBuilder takeSplits() {
105
        StringBuilder temp = splits;
1✔
106
        splits = new StringBuilder();
1✔
107
        return temp;
1✔
108
    }
109

110
    public void cached(Resolved data, Runnable runnable) {
111
        lineBuffer.cached(path, data, runnable, p -> append("*reference* " + p));
1✔
112
    }
1✔
113

114
    public DumpingBuffer append(String s) {
115
        length = lineBuffer.append(takeSplits(), s).length();
1✔
116
        return this;
1✔
117
    }
118

119
    public DumpingBuffer append(Throwable e) {
120
        return append("*throw* " + extractException(e).orElse(e));
1✔
121
    }
122

123
    public String content() {
124
        return lineBuffer.toString();
1✔
125
    }
126

127
    public DumpingBuffer appendThen(String then) {
128
        splits.append(then);
1✔
129
        return this;
1✔
130
    }
131

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

137
    public DumpingBuffer optionalNewLine() {
138
        if (length != lineBuffer.length())
1✔
139
            newLine();
1✔
140
        return this;
1✔
141
    }
142

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

150
        public LineBuffer(DALRuntimeContext runtimeContext) {
1✔
151
            this.runtimeContext = runtimeContext;
1✔
152
        }
1✔
153

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

165
        public int length() {
166
            return stringBuilder.length();
1✔
167
        }
168

169
        @Override
170
        public String toString() {
171
            return stringBuilder.toString();
1✔
172
        }
173

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

UNCOV
191
    public static class MaximizeDump extends RuntimeException {
×
192
    }
193
}
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