-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implements status, hashkv, defrag command (#91)
Signed-off-by: Yukihiko Sohda <yukihiko.sohda@gmail.com>
- Loading branch information
Showing
7 changed files
with
143 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/com/ibm/etcd/client/maintenance/EtcdMaintenanceClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.ibm.etcd.client.maintenance; | ||
|
||
import com.google.common.util.concurrent.ListenableFuture; | ||
import com.ibm.etcd.api.*; | ||
import com.ibm.etcd.client.GrpcClient; | ||
import io.grpc.MethodDescriptor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class EtcdMaintenanceClient implements MaintenanceClient { | ||
private static final Logger logger = LoggerFactory.getLogger(EtcdMaintenanceClient.class); | ||
|
||
private static final MethodDescriptor<StatusRequest,StatusResponse> METHOD_ENDPOINT_STATUS = | ||
MaintenanceGrpc.getStatusMethod(); | ||
private static final MethodDescriptor<HashKVRequest,HashKVResponse> METHOD_ENDPOINT_HASHKV = | ||
MaintenanceGrpc.getHashKVMethod(); | ||
private static final MethodDescriptor<DefragmentRequest,DefragmentResponse> METHOD_ENDPOINT_DEFRAG = | ||
MaintenanceGrpc.getDefragmentMethod(); | ||
|
||
private final GrpcClient client; | ||
|
||
public EtcdMaintenanceClient(GrpcClient client) { | ||
this.client = client; | ||
} | ||
|
||
@Override | ||
public ListenableFuture<StatusResponse> status() { | ||
return client.call(METHOD_ENDPOINT_STATUS, StatusRequest.newBuilder().build(), false); | ||
} | ||
|
||
@Override | ||
public ListenableFuture<HashKVResponse> hashkv() { | ||
return client.call(METHOD_ENDPOINT_HASHKV, HashKVRequest.newBuilder().build(), false); | ||
} | ||
|
||
@Override | ||
public ListenableFuture<DefragmentResponse> defrag() { | ||
return client.call(METHOD_ENDPOINT_DEFRAG, DefragmentRequest.newBuilder().build(), false); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/ibm/etcd/client/maintenance/MaintenanceClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.ibm.etcd.client.maintenance; | ||
|
||
import com.google.common.util.concurrent.ListenableFuture; | ||
import com.ibm.etcd.api.HashKVResponse; | ||
import com.ibm.etcd.api.StatusResponse; | ||
import com.ibm.etcd.api.DefragmentResponse; | ||
|
||
public interface MaintenanceClient { | ||
/** | ||
* | ||
* @return future for {@link StatusResponse} | ||
*/ | ||
ListenableFuture<StatusResponse> status(); | ||
|
||
/** | ||
* | ||
* @return future for {@link HashKVResponse} | ||
*/ | ||
ListenableFuture<HashKVResponse> hashkv(); | ||
|
||
/** | ||
* | ||
* @return future for {@link DefragmentResponse} | ||
*/ | ||
ListenableFuture<DefragmentResponse> defrag(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.ibm.etcd.client; | ||
|
||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import com.ibm.etcd.api.*; | ||
import com.ibm.etcd.client.maintenance.MaintenanceClient; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class MaintenanceTest { | ||
static KvStoreClient client; | ||
|
||
static MaintenanceClient maintenanceClient; | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
client = EtcdClient.forEndpoint("localhost", 2379) | ||
.withPlainText().build(); | ||
maintenanceClient = client.getMaintenanceClient(); | ||
} | ||
@AfterClass | ||
public static void teardown() throws Exception { | ||
if (client != null) { | ||
client.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testStatus() throws Exception { | ||
StatusResponse resp = maintenanceClient.status().get(1, SECONDS); | ||
assertNotNull(resp.getVersion()); | ||
assertTrue(resp.getDbSize() > 0L); | ||
assertTrue(resp.getDbSizeInUse() > 0L); | ||
assertTrue(resp.hasHeader()); | ||
assertTrue(resp.getHeader().getRevision() > 0L); | ||
} | ||
|
||
@Test | ||
public void testHashkv() throws Exception { | ||
HashKVResponse resp = maintenanceClient.hashkv().get(1, SECONDS); | ||
assertNotNull(resp); | ||
assertTrue(resp.getHash() != 0L); | ||
assertTrue(resp.hasHeader()); | ||
assertTrue(resp.getHeader().getRevision() > 0L); | ||
} | ||
|
||
@Test | ||
public void testDefrag() throws Exception { | ||
DefragmentResponse resp = maintenanceClient.defrag().get(5, SECONDS); | ||
assertNotNull(resp); | ||
} | ||
} |