Skip to content

Commit

Permalink
additional Tests (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArjunM98 authored Jan 29, 2021
1 parent 387078a commit aae2dd8
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions src/testing/AdditionalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
public class AdditionalTest extends TestCase {

private KVStore kvClient;
private KVStore kvClientAddition;


public void setUp() {
kvClient = new KVStore("localhost", 50000);
kvClientAddition = new KVStore("localhost", 50000);
try {
kvClient.connect();
kvClientAddition.connect();
} catch (Exception e) {
}
}
Expand Down Expand Up @@ -125,28 +129,39 @@ public void testDeletedKVs() throws Exception {
}

/**
* Ensure that we're able to get each of the possible message statuses
* Ensure that we only respond to requests of keys in the appropriate size range
*/
@Test
public void testMessageStatus() throws Exception {
// Test PUTs
assertEquals(KVMessage.StatusType.PUT_SUCCESS, kvClient.put("key", "value").getStatus());
assertEquals(KVMessage.StatusType.PUT_UPDATE, kvClient.put("key", "new value").getStatus());
// TODO: how to force PUT_ERROR?

// Test GETs
assertEquals(KVMessage.StatusType.GET_SUCCESS, kvClient.get("key").getStatus());
assertEquals(KVMessage.StatusType.GET_ERROR, kvClient.get("nonexistent_key").getStatus());
public void testMaxKeyError() throws Exception {
char[] bigKey = new char[KVStore.MAX_KEY_SIZE + 1];
Arrays.fill(bigKey, 'x');
assertEquals(KVMessage.StatusType.FAILED, kvClient.get(String.valueOf(bigKey)).getStatus());
}

// Test client-side failures
/**
* Ensure that we only respond to requests of values in the appropriate size range
*/
@Test
public void testMaxValueError() throws Exception {
char[] bigKey = new char[KVStore.MAX_KEY_SIZE + 1], bigValue = new char[KVStore.MAX_VALUE_SIZE + 1];
Arrays.fill(bigKey, 'x');
Arrays.fill(bigValue, 'x');
assertEquals(KVMessage.StatusType.FAILED, kvClient.get(String.valueOf(bigKey)).getStatus());
assertEquals(KVMessage.StatusType.FAILED, kvClient.put(String.valueOf(bigKey), "small value").getStatus());
assertEquals(KVMessage.StatusType.FAILED, kvClient.put("small_key", String.valueOf(bigValue)).getStatus());
}

/**
* Ensure that we only respond to requests of values in the appropriate size range
*/
@Test
public void testMultipleClientAccess() throws Exception {
String key = "test1Key";
String value = "test1Val";

KVMessage resClient1 = kvClient.put(key, value);
KVMessage resClient2 = kvClientAddition.get(key);

// Test server-side failures
// TODO: but how? would require malformed protobuf
assertEquals(KVMessage.StatusType.PUT_SUCCESS, resClient1.getStatus());
assertEquals(value, resClient2.getValue());
}
}

0 comments on commit aae2dd8

Please sign in to comment.