-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
96 additions
and
926 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
45 changes: 22 additions & 23 deletions
45
scalardb-test/src/main/java/kelpie/scalardb/sensor/SensorCommon.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 |
---|---|---|
@@ -1,62 +1,61 @@ | ||
package kelpie.scalardb.sensor; | ||
|
||
import com.scalar.db.api.Consistency; | ||
import com.scalar.db.api.DistributedTransactionManager; | ||
import com.scalar.db.api.Put; | ||
import com.scalar.db.api.Result; | ||
import com.scalar.db.api.Scan; | ||
import com.scalar.db.io.IntValue; | ||
import com.scalar.db.transaction.consensuscommit.TransactionResult; | ||
import com.scalar.db.io.Key; | ||
import com.scalar.kelpie.config.Config; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.OptionalInt; | ||
import java.util.Set; | ||
import java.util.stream.IntStream; | ||
import kelpie.scalardb.Common; | ||
|
||
public class SensorCommon { | ||
private static final String KEYSPACE = "sensor"; | ||
private static final String NAMESPACE = "sensor"; | ||
private static final String TABLE = "tx_sensor"; | ||
private static final String TIMESTAMP = "timestamp"; | ||
private static final String DEVICE_ID = "device_id"; | ||
private static final String REVISION = "revision"; | ||
|
||
public static DistributedTransactionManager getTransactionManager(Config config) { | ||
return Common.getTransactionManager(config, KEYSPACE, TABLE); | ||
} | ||
|
||
public static Scan prepareScan(int timestamp) { | ||
Key partitionKey = new Key(new IntValue(TIMESTAMP, timestamp)); | ||
|
||
return new Scan(partitionKey) | ||
.withOrdering(new Scan.Ordering(DEVICE_ID, Scan.Ordering.Order.ASC)) | ||
.withConsistency(Consistency.LINEARIZABLE); | ||
Key partitionKey = Key.ofInt(TIMESTAMP, timestamp); | ||
return Scan.newBuilder() | ||
.namespace(NAMESPACE) | ||
.table(TABLE) | ||
.partitionKey(partitionKey) | ||
.ordering(Scan.Ordering.asc(DEVICE_ID)) | ||
.consistency(Consistency.LINEARIZABLE) | ||
.build(); | ||
} | ||
|
||
public static Put preparePut(int timestamp, int deviceId, int revision) { | ||
Key partitionKey = new Key(new IntValue(TIMESTAMP, timestamp)); | ||
Key clusteringKey = new Key(new IntValue(DEVICE_ID, deviceId)); | ||
return new Put(partitionKey, clusteringKey) | ||
.withConsistency(Consistency.LINEARIZABLE) | ||
.withValue(new IntValue(REVISION, revision)); | ||
Key partitionKey = Key.ofInt(TIMESTAMP, timestamp); | ||
Key clusteringKey = Key.ofInt(DEVICE_ID, deviceId); | ||
return Put.newBuilder() | ||
.namespace(NAMESPACE) | ||
.table(TABLE) | ||
.partitionKey(partitionKey) | ||
.clusteringKey(clusteringKey) | ||
.consistency(Consistency.LINEARIZABLE) | ||
.intValue(REVISION, revision) | ||
.build(); | ||
} | ||
|
||
public static boolean hasDuplicatedRevision(List<Result> results) { | ||
IntStream revisions = results.stream().mapToInt(r -> getRevisionFromResult(r)); | ||
IntStream revisions = results.stream().mapToInt(SensorCommon::getRevisionFromResult); | ||
|
||
Set<Integer> tempSet = new HashSet<>(); | ||
return revisions.anyMatch(rev -> !tempSet.add(rev)); | ||
} | ||
|
||
public static int getMaxRevision(List<Result> results) { | ||
OptionalInt maxRevision = results.stream().mapToInt(r -> getRevisionFromResult(r)).max(); | ||
OptionalInt maxRevision = results.stream().mapToInt(SensorCommon::getRevisionFromResult).max(); | ||
|
||
return maxRevision.orElse(0); | ||
} | ||
|
||
private static int getRevisionFromResult(Result result) { | ||
return ((IntValue) result.getValue(REVISION).get()).get(); | ||
return result.getInt(REVISION); | ||
} | ||
} |
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
112 changes: 0 additions & 112 deletions
112
scalardb-test/src/main/java/kelpie/scalardb/storage/MultipleClusteringKeyPreparer.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.