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

wz2cool / local-queue / #12

29 Jan 2025 08:22AM UTC coverage: 93.366% (+0.5%) from 92.857%
#12

push

wz2cool
add consumeFrom

1 of 1 new or added line in 1 file covered. (100.0%)

11 existing lines in 3 files now uncovered.

380 of 407 relevant lines covered (93.37%)

0.93 hits per line

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

97.92
/src/main/java/com/github/wz2cool/localqueue/model/config/SimpleConsumerConfig.java
1
package com.github.wz2cool.localqueue.model.config;
2

3
import com.github.wz2cool.localqueue.model.enums.ConsumeFromWhere;
4

5
import java.io.File;
6
import java.util.Objects;
7

8
public class SimpleConsumerConfig {
9

10
    private final File dataDir;
11

12
    private final File positionFile;
13

14
    private final String consumerId;
15

16
    private final long pullInterval;
17

18
    private final int cacheSize;
19

20
    private final long flushPositionInterval;
21

22
    private final ConsumeFromWhere consumeFromWhere;
23

24
    private SimpleConsumerConfig(final Builder builder) {
1✔
25
        this.dataDir = builder.dataDir;
1✔
26
        this.positionFile = builder.positionFile;
1✔
27
        this.consumerId = builder.consumerId;
1✔
28
        this.pullInterval = builder.pullInterval;
1✔
29
        this.cacheSize = builder.cacheSize;
1✔
30
        this.flushPositionInterval = builder.flushPositionInterval;
1✔
31
        this.consumeFromWhere = builder.consumeFromWhere;
1✔
32
    }
1✔
33

34
    public File getDataDir() {
35
        return dataDir;
1✔
36
    }
37

38
    public File getPositionFile() {
39
        return positionFile;
1✔
40
    }
41

42
    public String getConsumerId() {
43
        return consumerId;
1✔
44
    }
45

46
    public long getPullInterval() {
47
        return pullInterval;
1✔
48
    }
49

50
    public int getCacheSize() {
51
        return cacheSize;
1✔
52
    }
53

54
    public long getFlushPositionInterval() {
55
        return flushPositionInterval;
1✔
56
    }
57

58
    public ConsumeFromWhere getConsumeFromWhere() {
59
        return consumeFromWhere;
1✔
60
    }
61

62
    public static class Builder {
1✔
63

64
        private File dataDir;
65

66
        private File positionFile;
67

68
        private String consumerId;
69

70
        private long pullInterval = 10;
1✔
71

72
        private int cacheSize = 10000;
1✔
73

74
        private long flushPositionInterval = 100;
1✔
75

76
        private ConsumeFromWhere consumeFromWhere = ConsumeFromWhere.LAST;
1✔
77

78
        public Builder setDataDir(File dataDir) {
79
            this.dataDir = dataDir;
1✔
80
            return this;
1✔
81
        }
82

83
        public Builder setPositionFile(File positionFile) {
84
            this.positionFile = positionFile;
1✔
85
            return this;
1✔
86
        }
87

88
        public Builder setConsumerId(String consumerId) {
89
            this.consumerId = consumerId;
1✔
90
            return this;
1✔
91
        }
92

93
        public Builder setPullInterval(long pullInterval) {
94
            this.pullInterval = pullInterval;
1✔
95
            return this;
1✔
96
        }
97

98
        public Builder setCacheSize(int cacheSize) {
99
            this.cacheSize = cacheSize;
1✔
100
            return this;
1✔
101
        }
102

103
        public Builder setFlushPositionInterval(long flushPositionInterval) {
104
            this.flushPositionInterval = flushPositionInterval;
1✔
105
            return this;
1✔
106
        }
107

108
        public Builder setConsumeFromWhere(ConsumeFromWhere consumeFromWhere) {
109
            this.consumeFromWhere = consumeFromWhere;
1✔
110
            return this;
1✔
111
        }
112

113
        public SimpleConsumerConfig build() {
114
            if (Objects.isNull(dataDir)) {
1✔
115
                throw new IllegalArgumentException("dataDir cannot be null");
1✔
116
            }
117

118
            if (Objects.isNull(consumerId) || consumerId.isEmpty()) {
1✔
119
                // 如果没有就给默认
120
                throw new IllegalArgumentException("consumerId cannot be null or empty");
1✔
121
            }
122

123
            if (cacheSize <= 0) {
1✔
124
                throw new IllegalArgumentException("cacheSize should > 0");
1✔
125
            }
126

127
            if (flushPositionInterval <= 0) {
1✔
128
                throw new IllegalArgumentException("flushPositionInterval should > 0");
1✔
129
            }
130

131
            if (Objects.isNull(positionFile)) {
1✔
132
                // 如果没有就给默认
133
                this.positionFile = new File(dataDir, "position.dat");
1✔
134
            }
135

136
            if (Objects.isNull(consumeFromWhere)) {
1✔
UNCOV
137
                throw new IllegalArgumentException("consumeFromWhere cannot be null");
×
138
            }
139

140

141
            return new SimpleConsumerConfig(this);
1✔
142
        }
143

144
    }
145
}
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