Created
June 21, 2012 17:39
-
-
Save andresilva/2967278 to your computer and use it in GitHub Desktop.
Alternator bug scenario
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
import com.michelboudreau.alternator.*; | |
import com.amazonaws.AmazonClientException; | |
import com.amazonaws.AmazonServiceException; | |
import com.amazonaws.services.dynamodb.AmazonDynamoDB; | |
import com.amazonaws.services.dynamodb.model.*; | |
import java.util.*; | |
public class Main { | |
static private AlternatorDBClient client; | |
static private AlternatorDB db; | |
public static void setUp() throws Exception { | |
client = new AlternatorDBClient(); | |
db = new AlternatorDB().start(); | |
} | |
public static void tearDown() throws Exception { | |
db.stop(); | |
} | |
public static void createTables() throws Exception { | |
KeySchemaElement hashKey = new KeySchemaElement().withAttributeName("Key").withAttributeType("S"); | |
KeySchema ks = new KeySchema().withHashKeyElement(hashKey); | |
ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput() | |
.withReadCapacityUnits(10L) | |
.withWriteCapacityUnits(10L); | |
CreateTableRequest request = new CreateTableRequest() | |
.withTableName("Test") | |
.withKeySchema(ks) | |
.withProvisionedThroughput(provisionedThroughput); | |
client.createTable(request); | |
} | |
public static void put() throws Exception { | |
AttributeValue key = new AttributeValue().withS("1"); | |
AttributeValue a1 = new AttributeValue().withS("a1"); | |
AttributeValue a2 = new AttributeValue().withS("a2"); | |
Map<String, AttributeValue> item = new HashMap<String, AttributeValue>(); | |
item.put("Key", key); | |
item.put("a1", a1); | |
item.put("a2", a2); | |
PutItemRequest itemRequest = new PutItemRequest("Test", item); | |
client.putItem(itemRequest); | |
} | |
public static void get() throws Exception { | |
List attributes = new LinkedList<String>(); | |
attributes.add("a1"); | |
attributes.add("a2"); | |
attributes.add("a3"); | |
GetItemRequest getItemRequest = new GetItemRequest("Test", new Key(new AttributeValue("1"))) | |
.withAttributesToGet(attributes).withConsistentRead(true); | |
GetItemResult result = client.getItem(getItemRequest); | |
result.getItem(); | |
} | |
public static void main(String[] args) throws Exception { | |
setUp(); | |
createTables(); | |
put(); | |
get(); | |
tearDown(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment