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

wz2cool / local-queue / #38

01 Feb 2025 12:36PM UTC coverage: 91.85% (-0.02%) from 91.871%
#38

push

web-flow
Merge pull request #6 from wz2cool/0.1.2

0.1.2

113 of 127 new or added lines in 9 files covered. (88.98%)

586 of 638 relevant lines covered (91.85%)

0.92 hits per line

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

97.18
/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
import com.github.wz2cool.localqueue.model.enums.RollCycleType;
5

6
import java.io.File;
7
import java.util.Objects;
8
import java.util.TimeZone;
9

10
public class SimpleConsumerConfig {
11

12
    private final File dataDir;
13

14
    private final File positionFile;
15

16
    private final String consumerId;
17

18
    private final long pullInterval;
19

20
    private final long fillCacheInterval;
21

22
    private final int cacheSize;
23

24
    private final long flushPositionInterval;
25

26
    private final ConsumeFromWhere consumeFromWhere;
27

28
    private final RollCycleType rollCycleType;
29

30
    private final TimeZone timeZone;
31

32
    private SimpleConsumerConfig(final Builder builder) {
1✔
33
        this.dataDir = builder.dataDir;
1✔
34
        this.positionFile = builder.positionFile;
1✔
35
        this.consumerId = builder.consumerId;
1✔
36
        this.pullInterval = builder.pullInterval;
1✔
37
        this.fillCacheInterval = builder.fillCacheInterval;
1✔
38
        this.cacheSize = builder.cacheSize;
1✔
39
        this.flushPositionInterval = builder.flushPositionInterval;
1✔
40
        this.consumeFromWhere = builder.consumeFromWhere;
1✔
41
        this.rollCycleType = builder.rollCycleType;
1✔
42
        this.timeZone = builder.timeZone;
1✔
43
    }
1✔
44

45
    public File getDataDir() {
46
        return dataDir;
1✔
47
    }
48

49
    public File getPositionFile() {
50
        return positionFile;
1✔
51
    }
52

53
    public String getConsumerId() {
54
        return consumerId;
1✔
55
    }
56

57
    public long getPullInterval() {
58
        return pullInterval;
1✔
59
    }
60

61
    public int getCacheSize() {
62
        return cacheSize;
1✔
63
    }
64

65
    public long getFlushPositionInterval() {
66
        return flushPositionInterval;
1✔
67
    }
68

69
    public ConsumeFromWhere getConsumeFromWhere() {
70
        return consumeFromWhere;
1✔
71
    }
72

73
    public RollCycleType getRollCycleType() {
74
        return rollCycleType;
1✔
75
    }
76

77
    public long getFillCacheInterval() {
78
        return fillCacheInterval;
1✔
79
    }
80

81
    public TimeZone getTimeZone() {
82
        return timeZone;
1✔
83
    }
84

85
    public static class Builder {
1✔
86

87
        private File dataDir;
88

89
        private File positionFile;
90

91
        private String consumerId;
92

93
        private long pullInterval = 10;
1✔
94

95
        private int cacheSize = 10000;
1✔
96

97
        private long fillCacheInterval = 500;
1✔
98

99
        private long flushPositionInterval = 100;
1✔
100

101
        private ConsumeFromWhere consumeFromWhere = ConsumeFromWhere.LAST;
1✔
102

103
        private RollCycleType rollCycleType = RollCycleType.HOURLY;
1✔
104

105
        private TimeZone timeZone = TimeZone.getDefault();
1✔
106

107
        public Builder setDataDir(File dataDir) {
108
            this.dataDir = dataDir;
1✔
109
            return this;
1✔
110
        }
111

112
        public Builder setPositionFile(File positionFile) {
113
            this.positionFile = positionFile;
1✔
114
            return this;
1✔
115
        }
116

117
        public Builder setConsumerId(String consumerId) {
118
            this.consumerId = consumerId;
1✔
119
            return this;
1✔
120
        }
121

122
        public Builder setPullInterval(long pullInterval) {
123
            this.pullInterval = pullInterval;
1✔
124
            return this;
1✔
125
        }
126

127
        public Builder setCacheSize(int cacheSize) {
128
            this.cacheSize = cacheSize;
1✔
129
            return this;
1✔
130
        }
131

132
        public Builder setFlushPositionInterval(long flushPositionInterval) {
133
            this.flushPositionInterval = flushPositionInterval;
1✔
134
            return this;
1✔
135
        }
136

137
        public Builder setConsumeFromWhere(ConsumeFromWhere consumeFromWhere) {
138
            this.consumeFromWhere = consumeFromWhere;
1✔
139
            return this;
1✔
140
        }
141

142
        public Builder setRollCycleType(RollCycleType rollCycleType) {
143
            this.rollCycleType = rollCycleType;
1✔
144
            return this;
1✔
145
        }
146

147
        public Builder setFillCacheInterval(long fillCacheInterval) {
148
            this.fillCacheInterval = fillCacheInterval;
1✔
149
            return this;
1✔
150
        }
151

152
        public Builder setTimeZone(TimeZone timeZone) {
153
            this.timeZone = timeZone;
1✔
154
            return this;
1✔
155
        }
156

157
        public SimpleConsumerConfig build() {
158
            if (Objects.isNull(dataDir)) {
1✔
159
                throw new IllegalArgumentException("dataDir cannot be null");
1✔
160
            }
161

162
            if (Objects.isNull(consumerId) || consumerId.isEmpty()) {
1✔
163
                // 如果没有就给默认
164
                throw new IllegalArgumentException("consumerId cannot be null or empty");
1✔
165
            }
166

167
            if (cacheSize <= 0) {
1✔
168
                throw new IllegalArgumentException("cacheSize should > 0");
1✔
169
            }
170

171
            if (flushPositionInterval <= 0) {
1✔
172
                throw new IllegalArgumentException("flushPositionInterval should > 0");
1✔
173
            }
174

175
            if (Objects.isNull(positionFile)) {
1✔
176
                // 如果没有就给默认
177
                this.positionFile = new File(dataDir, "position.dat");
1✔
178
            }
179

180
            if (Objects.isNull(consumeFromWhere)) {
1✔
181
                throw new IllegalArgumentException("consumeFromWhere cannot be null");
1✔
182
            }
183

184
            if (pullInterval <= 0) {
1✔
185
                throw new IllegalArgumentException("pullInterval should > 0");
1✔
186
            }
187

188
            if (fillCacheInterval <= 0) {
1✔
189
                throw new IllegalArgumentException("fillCacheInterval should > 0");
1✔
190
            }
191

192
            if (Objects.isNull(rollCycleType)) {
1✔
NEW
193
                throw new IllegalArgumentException("rollCycleType cannot be null");
×
194
            }
195

196
            if (Objects.isNull(timeZone)) {
1✔
NEW
197
                throw new IllegalArgumentException("timeZone cannot be null");
×
198
            }
199

200
            return new SimpleConsumerConfig(this);
1✔
201
        }
202

203
    }
204
}
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