Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ public AppendResult putKey(
return AppendResult.SUCCESS;
}

AppendResult result = AppendResult.UNKNOWN_ERROR;
for (int i = 0; i < 3; i++) {
AppendResult result = this.currentWriteFile.putKey(
result = this.currentWriteFile.putKey(
topic, topicId, queueId, keySet, offset, size, timestamp);

if (AppendResult.SUCCESS.equals(result)) {
Expand All @@ -225,7 +226,7 @@ public AppendResult putKey(

log.error("IndexStoreService#putKey, put key three times return error, topic={}, topicId={}, queueId={}, keySize={}, timestamp={}",
topic, topicId, queueId, keySet.size(), timestamp);
return AppendResult.SUCCESS;
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -110,6 +111,22 @@ public void basicServiceTest() throws InterruptedException {
Assert.assertEquals(3, timeStoreTable.size());
}

@Test
public void putKeyReturnsFileFullAfterRetriesExhausted() throws IllegalAccessException {
IndexStoreService service = Mockito.spy(new IndexStoreService(fileAllocator, filePath, false));
IndexFile fullIndexFile = Mockito.mock(IndexFile.class);
Mockito.when(fullIndexFile.putKey(
TOPIC_NAME, TOPIC_ID, QUEUE_ID, KEY_SET, MESSAGE_OFFSET, MESSAGE_SIZE, 1L))
.thenReturn(AppendResult.FILE_FULL);
FieldUtils.writeField(service, "currentWriteFile", fullIndexFile, true);
Mockito.doNothing().when(service).createNewIndexFile(Mockito.anyLong());

Assert.assertEquals(AppendResult.FILE_FULL, service.putKey(
TOPIC_NAME, TOPIC_ID, QUEUE_ID, KEY_SET, MESSAGE_OFFSET, MESSAGE_SIZE, 1L));
Mockito.verify(fullIndexFile, Mockito.times(3)).putKey(
TOPIC_NAME, TOPIC_ID, QUEUE_ID, KEY_SET, MESSAGE_OFFSET, MESSAGE_SIZE, 1L);
}

@Test
public void doConvertOldFormatTest() throws IOException {
indexService = new IndexStoreService(fileAllocator, filePath);
Expand Down Expand Up @@ -392,4 +409,4 @@ public void queryCrossFileBoundaryTest() throws InterruptedException, ExecutionE

Assert.assertFalse("Should find index items from file covering query range", results.isEmpty());
}
}
}
Loading