Skip to content
Merged
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
40 changes: 20 additions & 20 deletions src/main/java/com/aliyun/openservices/log/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -1498,12 +1498,12 @@ public GetCursorTimeResponse GetCursorTime(GetCursorTimeRequest request)
return getCursorTimeResponse;
}

public GetCursorTimeResponse GetPrevCursorTime(String project, String logStore,int shardId, String cursor) throws LogException {
if(cursor.isEmpty())
throw new LogException(ErrorCodes.INVALID_CURSOR, "empty cursor string", "");
long prv = Long.parseLong(new String(Base64.decodeBase64(cursor))) - 1;
if(prv >= 0){
cursor = new String(Base64.encodeBase64(Long.toString(prv).getBytes()));
public GetCursorTimeResponse GetPrevCursorTime(String project, String logStore,int shardId, String cursor) throws LogException {
if (cursor == null || cursor.isEmpty())
throw new LogException(ErrorCodes.INVALID_CURSOR, "empty cursor string", "");
long prv = Long.parseLong(new String(Base64.decodeBase64(cursor))) - 1;
if(prv >= 0){
cursor = new String(Base64.encodeBase64(Long.toString(prv).getBytes()));
}
else{
throw new LogException(ErrorCodes.INVALID_CURSOR, "this cursor has no prev value", "");
Expand All @@ -1520,13 +1520,13 @@ public GetCursorTimeResponse GetCursorTime(String project, String logStore,
return GetCursorTime(request);
}

public ListShardResponse SplitShard(String project, String logStore,
int shardId, String midHash) throws LogException {
CodingUtils.assertStringNotNullOrEmpty(project, "project");
CodingUtils.assertStringNotNullOrEmpty(logStore, "logStore");
CodingUtils.assertStringNotNullOrEmpty(logStore, "shardId");
return SplitShard(new SplitShardRequest(project, logStore, shardId, midHash));
}
public ListShardResponse SplitShard(String project, String logStore,
int shardId, String midHash) throws LogException {
CodingUtils.assertStringNotNullOrEmpty(project, "project");
CodingUtils.assertStringNotNullOrEmpty(logStore, "logStore");
Args.check(shardId >= 0, "shardId must be >= 0");
return SplitShard(new SplitShardRequest(project, logStore, shardId, midHash));
}

public ListShardResponse SplitShard(SplitShardRequest request)
throws LogException {
Expand All @@ -1548,13 +1548,13 @@ public ListShardResponse SplitShard(SplitShardRequest request)
return new ListShardResponse(resHeaders, shards);
}

public ListShardResponse MergeShards(String project, String logStore,
int shardId) throws LogException {
CodingUtils.assertStringNotNullOrEmpty(project, "project");
CodingUtils.assertStringNotNullOrEmpty(logStore, "logStore");
CodingUtils.assertStringNotNullOrEmpty(logStore, "shardId");
return MergeShards(new MergeShardsRequest(project, logStore, shardId));
}
public ListShardResponse MergeShards(String project, String logStore,
int shardId) throws LogException {
CodingUtils.assertStringNotNullOrEmpty(project, "project");
CodingUtils.assertStringNotNullOrEmpty(logStore, "logStore");
Args.check(shardId >= 0, "shardId must be >= 0");
return MergeShards(new MergeShardsRequest(project, logStore, shardId));
}

public ListShardResponse MergeShards(MergeShardsRequest request)
throws LogException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.aliyun.openservices.log;

import com.aliyun.openservices.log.exception.LogException;
import com.aliyun.openservices.log.internal.ErrorCodes;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

public class ClientShardValidationTest {
private static final Client client = new Client(
"http://mock-sls.aliyun-inc.com",
"test-access-key-id",
"test-access-key");

@Test
public void testSplitShardRejectsNegativeShardId() throws LogException {
try {
client.SplitShard("project", "logstore", -1, "");
fail("Should reject negative shardId");
} catch (IllegalArgumentException ex) {
assertEquals("shardId must be >= 0", ex.getMessage());
}
}

@Test
public void testMergeShardsRejectsNegativeShardId() throws LogException {
try {
client.MergeShards("project", "logstore", -1);
fail("Should reject negative shardId");
} catch (IllegalArgumentException ex) {
assertEquals("shardId must be >= 0", ex.getMessage());
}
}

@Test
public void testGetPrevCursorTimeRejectsNullCursor() {
try {
client.GetPrevCursorTime("project", "logstore", 0, null);
fail("Should reject null cursor");
} catch (LogException ex) {
assertEquals(ErrorCodes.INVALID_CURSOR, ex.GetErrorCode());
assertEquals("empty cursor string", ex.GetErrorMessage());
}
}
}
Loading