Skip to content

Commit 9eb716f

Browse files
committed
wait for more time for specific size
1 parent 436adf9 commit 9eb716f

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

redis/redis-core/src/test/java/com/ctrip/xpipe/redis/core/server/FakeRedisServer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void addCommandsListener(FakeRedisServerAction fakeRedisServerAction) {
134134
}
135135

136136

137-
public Object currentCommands() {
137+
public String currentCommands() {
138138
return commands;
139139
}
140140

redis/redis-keeper/src/test/java/com/ctrip/xpipe/redis/keeper/AbstractRedisKeeperTest.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ public void beforeFileData() {
180180
return new String(bachannel.getResult());
181181
}
182182

183-
public String readCommandFileTilEnd(final ReplicationStore replicationStore) throws IOException {
183+
public String readCommandFileTilEnd(final ReplicationStore replicationStore, int expectedLen) throws IOException {
184184

185-
return readCommandFileTilEnd(0, replicationStore);
185+
return readCommandFileTilEnd(0, replicationStore, expectedLen);
186186
}
187187

188188

189-
public String readCommandFileTilEnd(final long beginOffset, final ReplicationStore replicationStore) throws IOException {
189+
public String readCommandFileTilEnd(final long beginOffset, final ReplicationStore replicationStore, int expectedLen) throws IOException {
190190

191191
final ByteArrayOutputStream baous = new ByteArrayOutputStream();
192192
new Thread() {
@@ -195,11 +195,11 @@ public void run() {
195195
try {
196196
doRun();
197197
} catch (Exception e) {
198-
e.printStackTrace();
198+
logger.error("[run]", e);
199199
}
200200
}
201201

202-
private void doRun() throws IOException {
202+
private void doRun() throws IOException{
203203
replicationStore.addCommandsListener(replicationStore.beginOffsetWhenCreated() + beginOffset, new CommandsListener() {
204204

205205
@Override
@@ -231,13 +231,16 @@ public ChannelFuture onCommand(ReferenceFileRegion referenceFileRegion) {
231231
long equalCount = 0;
232232
while (true) {
233233
int currentSize = baous.size();
234+
if(expectedLen >= 0 && currentSize >= expectedLen){
235+
break;
236+
}
234237
if (currentSize != lastSize) {
235238
lastSize = currentSize;
236239
equalCount = 0;
237240
} else {
238241
equalCount++;
239242
}
240-
if (equalCount > 10) {
243+
if (equalCount > 100) {
241244
break;
242245
}
243246
sleep(10);

redis/redis-keeper/src/test/java/com/ctrip/xpipe/redis/keeper/impl/fakeredis/DefaultRedisKeeperServerConnectToFakeRedisTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void testReplicationData() throws Exception{
2828
String rdbContent = readRdbFileTilEnd(replicationStore);
2929
Assert.assertEquals(fakeRedisServer.getRdbContent(), rdbContent);
3030

31-
String commands = readCommandFileTilEnd(replicationStore);
31+
String commands = readCommandFileTilEnd(replicationStore, fakeRedisServer.currentCommands().length());
3232
Assert.assertEquals(fakeRedisServer.currentCommands(), commands);
3333
}
3434

redis/redis-keeper/src/test/java/com/ctrip/xpipe/redis/keeper/protocal/cmd/PsyncTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ private void assertResult() throws IOException, InterruptedException {
255255
replicationStore = (DefaultReplicationStore) replicationStoreManager.getCurrent();
256256

257257
String rdbResult = readRdbFileTilEnd(replicationStore);
258-
String commandResult = readCommandFileTilEnd(replicationStore);
258+
String commandResult = readCommandFileTilEnd(replicationStore, commandContent.length());
259259

260260
if(!isPartial){
261261
Assert.assertEquals(rdbContent, rdbResult);

redis/redis-keeper/src/test/java/com/ctrip/xpipe/redis/keeper/store/DefaultReplicationStoreTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void testReadWrite() throws Exception {
144144
buf.writeBytes(cmd.getBytes());
145145
store.getCommandStore().appendCommands(buf);
146146
}
147-
String result = readCommandFileTilEnd(store);
147+
String result = readCommandFileTilEnd(store, exp.length());
148148
assertEquals(exp.toString(), result);
149149
store.close();
150150
}

0 commit comments

Comments
 (0)