Created
July 20, 2015 22:34
-
-
Save jentfoo/9bec96163e2f4085a3c4 to your computer and use it in GitHub Desktop.
Failure repo code for Alternator issue #94
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
package crab.db; | |
import java.util.Iterator; | |
import java.util.List; | |
import org.junit.Before; | |
import org.junit.Test; | |
import com.amazonaws.services.dynamodbv2.document.DynamoDB; | |
import com.amazonaws.services.dynamodbv2.document.Item; | |
import com.amazonaws.services.dynamodbv2.document.ItemCollection; | |
import com.amazonaws.services.dynamodbv2.document.QueryOutcome; | |
import com.amazonaws.services.dynamodbv2.document.Table; | |
import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; | |
import com.amazonaws.services.dynamodbv2.document.utils.ValueMap; | |
import com.amazonaws.services.dynamodbv2.model.AttributeDefinition; | |
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; | |
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement; | |
import com.amazonaws.services.dynamodbv2.model.KeyType; | |
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput; | |
import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType; | |
import com.google.common.collect.ImmutableList; | |
import com.michelboudreau.alternator.AlternatorDB; | |
import com.michelboudreau.alternatorv2.AlternatorDBClientV2; | |
public class AlternatorFailure { | |
private static final String PRIMARY_HASH_KEY_CONTACT = "hashKey"; | |
private static final String PRIMARY_RANGE_KEY_ETAG = "rangeKey"; | |
private static final List<KeySchemaElement> KEY_SCHEMA; | |
private static final List<AttributeDefinition> ATTRIBUTE_SCHEMA; | |
static { | |
KEY_SCHEMA = ImmutableList.of(new KeySchemaElement(PRIMARY_HASH_KEY_CONTACT, KeyType.HASH), | |
new KeySchemaElement(PRIMARY_RANGE_KEY_ETAG, KeyType.RANGE)); | |
ATTRIBUTE_SCHEMA = ImmutableList.of(new AttributeDefinition(PRIMARY_HASH_KEY_CONTACT, | |
ScalarAttributeType.S), | |
new AttributeDefinition(PRIMARY_RANGE_KEY_ETAG, | |
ScalarAttributeType.S)); | |
} | |
private AlternatorDBClientV2 client; | |
private AlternatorDB db; | |
private Table dynamoTable; | |
@Before | |
public void setUp() throws Exception { | |
this.client = new AlternatorDBClientV2(); | |
this.db = new AlternatorDB().start(); | |
DynamoDB dynamoDb = new DynamoDB(client); | |
ProvisionedThroughput pt = new ProvisionedThroughput(1000L, 1000L); | |
CreateTableRequest createTableRequest; | |
createTableRequest = new CreateTableRequest(ATTRIBUTE_SCHEMA, "tableName", KEY_SCHEMA, pt); | |
dynamoTable = dynamoDb.createTable(createTableRequest); | |
dynamoTable.waitForActive(); | |
} | |
@Test | |
public void runTest() throws InterruptedException { | |
String queryStr = PRIMARY_HASH_KEY_CONTACT + " = :v_hashKey AND " + | |
PRIMARY_RANGE_KEY_ETAG + " = :v_rangeKey"; | |
QuerySpec qSpec = new QuerySpec().withKeyConditionExpression(queryStr) | |
.withConsistentRead(true) | |
.withValueMap(new ValueMap().withString(":v_hashKey", | |
"foo") | |
.withString(":v_etag", "bar")); | |
ItemCollection<QueryOutcome> queryResult = dynamoTable.query(qSpec); | |
// the next call will fail | |
Iterator<Item> resultIt = queryResult.firstPage().iterator(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment