Here are the examples of the java api com.aerospike.client.Record taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
81 Examples
19
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
void insertCollection(String function) throws SQLException {
insert(format("insert into data (PK, collection) values (1, %s('[1, 2, 3]'))", function), 1);
Record record = client.get(null, new Key("test", "data", 1));
replacedertNotNull(record);
Map<String, Object> expectedData = new HashMap<>();
expectedData.put("collection", asList(1L, 2L, 3L));
replacedertEquals(expectedData, record.bins);
}
19
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
@Test
void insertDuplicateRow() throws SQLException {
insert("insert into people (PK, id, first_name, last_name, year_of_birth, kids_count) values (1, 1, 'John', 'Lennon', 1940, 2)", 1);
Record record = client.get(null, new Key("test", "people", 1));
replacedertNotNull(record);
Map<String, Object> expectedData = new HashMap<>();
expectedData.put("id", 1L);
expectedData.put("first_name", "John");
expectedData.put("last_name", "Lennon");
expectedData.put("year_of_birth", 1940L);
expectedData.put("kids_count", 2L);
replacedertEquals(expectedData, record.bins);
SQLException e = replacedertThrows(SQLException.clreplaced, () -> insert("insert into people (PK, id, first_name, last_name, year_of_birth, kids_count) values (1, 1, 'John', 'Lennon', 1940, 2)", 1));
replacedertTrue(e.getMessage().contains("Duplicate entries"));
}
19
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
@Test
void insertMap() throws SQLException {
insert("insert into data (PK, map) values (1, map('{\"one\": \"first\", \"two\": \"second\"}'))", 1);
Record record = client.get(null, new Key("test", "data", 1));
replacedertNotNull(record);
Map<String, Object> expectedData = new HashMap<>();
Map<String, Object> map = new HashMap<>();
map.put("one", "first");
map.put("two", "second");
expectedData.put("map", map);
replacedertEquals(expectedData, record.bins);
}
19
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
@Test
void insertUsingPreparedStatementAndExecute() throws SQLException {
Key key1 = new Key(NAMESPACE, DATA, 1);
replacedertNull(client.get(null, key1));
PreparedStatement ps = testConn.prepareStatement("insert into data (PK, text) values (?, ?)");
ps.setInt(1, 1);
ps.setString(2, "ok");
replacedertFalse(ps.execute());
Record record1 = client.get(null, key1);
replacedertEquals("ok", record1.getString("text"));
}
19
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
@Test
void insertAsciiStreams() throws SQLException {
Key key1 = new Key(NAMESPACE, DATA, 1);
replacedertNull(client.get(null, key1));
PreparedStatement ps = testConn.prepareStatement("insert into data (PK, ascii_stream, ascii_stream_i, ascii_stream_l) values (?, ?, ?, ?)");
String text = "hello, ascii stream!";
byte[] bytes = text.getBytes();
ps.setInt(1, 1);
ps.setAsciiStream(2, new ByteArrayInputStream(bytes));
ps.setAsciiStream(3, new ByteArrayInputStream(bytes), text.length());
ps.setAsciiStream(4, new ByteArrayInputStream(bytes), (long) text.length());
replacedertEquals(1, ps.executeUpdate());
Record record1 = client.get(null, key1);
replacedertNotNull(record1);
replacedertEquals(text, record1.getString("ascii_stream"));
replacedertEquals(text, record1.getString("ascii_stream_i"));
replacedertEquals(text, record1.getString("ascii_stream_l"));
}
19
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
@Test
void insertNClobs() throws SQLException {
Key key1 = new Key(NAMESPACE, DATA, 1);
replacedertNull(client.get(null, key1));
PreparedStatement ps = testConn.prepareStatement("insert into data (PK, clob, reader, limited_reader) values (?, ?, ?, ?)");
String text = "hello, clob!";
NClob clob = new StringClob();
clob.setString(1, text);
ps.setInt(1, 1);
ps.setNClob(2, clob);
ps.setNClob(3, new StringReader(text));
ps.setNClob(4, new StringReader(text), text.length());
replacedertEquals(1, ps.executeUpdate());
Record record1 = client.get(null, key1);
replacedertNotNull(record1);
replacedertEquals(text, record1.getString("clob"));
replacedertEquals(text, record1.getString("reader"));
replacedertEquals(text, record1.getString("limited_reader"));
}
19
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
@Test
void insertOneRowUsingPreparedStatement() throws SQLException {
PreparedStatement ps = testConn.prepareStatement("insert into people (PK, id, first_name, last_name, year_of_birth, kids_count) values (?, ?, ?, ?, ?, ?)");
ps.setInt(1, 1);
ps.setInt(2, 1);
ps.setString(3, "John");
ps.setString(4, "Lennon");
ps.setInt(5, 1940);
ps.setInt(6, 2);
int rowCount = ps.executeUpdate();
replacedertEquals(1, rowCount);
Record record = client.get(null, new Key("test", "people", 1));
replacedertNotNull(record);
Map<String, Object> expectedData = new HashMap<>();
expectedData.put("id", 1L);
expectedData.put("first_name", "John");
expectedData.put("last_name", "Lennon");
expectedData.put("year_of_birth", 1940L);
expectedData.put("kids_count", 2L);
replacedertEquals(expectedData, record.bins);
}
19
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
@ParameterizedTest(name = ARGUMENTS_PLACEHOLDER)
@ValueSource(strings = { "insert into people (PK, id, first_name, last_name, year_of_birth, kids_count) values (1, 1, 'John', 'Lennon', 1940, 2)", "insert into test.people (PK, id, first_name, last_name, year_of_birth, kids_count) values (1, 1, 'John', 'Lennon', 1940, 2)" })
void insertOneRow(String sql) throws SQLException {
insert(sql, 1);
Record record = client.get(null, new Key("test", "people", 1));
replacedertNotNull(record);
Map<String, Object> expectedData = new HashMap<>();
expectedData.put("id", 1L);
expectedData.put("first_name", "John");
expectedData.put("last_name", "Lennon");
expectedData.put("year_of_birth", 1940L);
expectedData.put("kids_count", 2L);
replacedertEquals(expectedData, record.bins);
}
19
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
@Test
void insertCharacterStreams() throws SQLException {
Key key1 = new Key(NAMESPACE, DATA, 1);
replacedertNull(client.get(null, key1));
PreparedStatement ps = testConn.prepareStatement("insert into data (PK, char_stream, char_stream_i, char_stream_l, nchar_stream, nchar_stream_l) values (?, ?, ?, ?, ?, ?)");
String text = "hello, character stream!";
ps.setInt(1, 1);
ps.setCharacterStream(2, new StringReader(text));
ps.setCharacterStream(3, new StringReader(text), text.length());
ps.setCharacterStream(4, new StringReader(text), (long) text.length());
ps.setNCharacterStream(5, new StringReader(text));
ps.setNCharacterStream(6, new StringReader(text), text.length());
replacedertEquals(1, ps.executeUpdate());
Record record1 = client.get(null, key1);
replacedertNotNull(record1);
replacedertEquals(text, record1.getString("char_stream"));
replacedertEquals(text, record1.getString("char_stream_i"));
replacedertEquals(text, record1.getString("char_stream_l"));
replacedertEquals(text, record1.getString("nchar_stream"));
replacedertEquals(text, record1.getString("nchar_stream_l"));
}
19
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
@ParameterizedTest(name = ARGUMENTS_PLACEHOLDER)
@ValueSource(strings = { "insert into data (PK, number, real, text, nothing) values (1, 1, 3.14, 'something', NULL)", "insert into data (PK, number, real, text, nothing) values (1, 1, 3.14, 'something', null)" })
void insertNull(String sql) throws SQLException {
insert(sql, 1);
Record record = client.get(null, new Key("test", "data", 1));
replacedertNotNull(record);
Map<String, Object> expectedData = new HashMap<>();
expectedData.put("number", 1L);
expectedData.put("real", 3.14);
expectedData.put("text", "something");
replacedertEquals(expectedData, record.bins);
}
19
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
@Test
void insertClobs() throws SQLException, IOException {
Key key1 = new Key(NAMESPACE, DATA, 1);
replacedertNull(client.get(null, key1));
PreparedStatement ps = testConn.prepareStatement("insert into data (PK, clob, reader, limited_reader) values (?, ?, ?, ?)");
String text = "hello, clob!";
Clob clob = new StringClob();
clob.setString(1, text);
ps.setInt(1, 1);
ps.setClob(2, clob);
ps.setClob(3, new StringReader(text));
ps.setClob(4, new StringReader(text), text.length());
// Wrong clob length
replacedertThrows(SQLException.clreplaced, () -> ps.setClob(4, new StringReader(text), text.length() + 1));
replacedertThrows(SQLException.clreplaced, () -> ps.setClob(4, new StringReader(text), text.length() - 1));
Reader exceptionalReader = mock(Reader.clreplaced);
when(exceptionalReader.read(any(), anyInt(), anyInt())).thenThrow(new IOException());
replacedertThrows(SQLException.clreplaced, () -> ps.setClob(4, exceptionalReader, 0));
replacedertThrows(SQLException.clreplaced, () -> ps.setClob(4, exceptionalReader));
InputStream exceptionalInputStream = mock(InputStream.clreplaced);
when(exceptionalInputStream.read(any(), anyInt(), anyInt())).thenThrow(new IOException());
replacedertThrows(SQLException.clreplaced, () -> ps.setBlob(4, exceptionalInputStream, 0));
replacedertThrows(SQLException.clreplaced, () -> ps.setBlob(4, exceptionalInputStream));
InputStream exceptionalInputStream2 = mock(InputStream.clreplaced);
when(exceptionalInputStream2.read(any(), anyInt(), anyInt())).thenThrow(new EOFException());
replacedertThrows(SQLException.clreplaced, () -> ps.setBlob(4, exceptionalInputStream2, 0));
replacedertEquals(1, ps.executeUpdate());
Record record1 = client.get(null, key1);
replacedertNotNull(record1);
replacedertEquals(text, record1.getString("clob"));
replacedertEquals(text, record1.getString("reader"));
replacedertEquals(text, record1.getString("limited_reader"));
}
19
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
@Test
void insertIgnoreDuplicateRow() throws SQLException {
insert("insert into people (PK, id, first_name, last_name, year_of_birth, kids_count) values (1, 1, 'John', 'Lennon', 1940, 2)", 1);
Record record = client.get(null, new Key("test", "people", 1));
replacedertNotNull(record);
replacedertEquals("John", record.getString("first_name"));
insert("insert ignore into people (PK, id, first_name, last_name, year_of_birth, kids_count) values (1, 1, 'John', 'Lennon', 1940, 2)", 1);
replacedertNotNull(record);
replacedertEquals("John", record.getString("first_name"));
}
19
Source : RecordExpressionEvaluator.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
@Override
protected Map<String, Object> toMap(Record record) {
return record.bins;
}
19
Source : AerospikeBatchQueryByPk.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
private static KeyRecord[] zip(Key[] keys, Record[] records) {
return IntStream.range(0, keys.length).mapToObj(i -> new KeyRecord(keys[i], records[i])).toArray(KeyRecord[]::new);
}
19
Source : BatchReadResponseTest.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
public clreplaced BatchReadResponseTest {
private static String ns = "test";
private static String set = "set";
private static String[] testBins = { "b1", "b2", "b3" };
private Record testRecord;
private Key testKey = new Key(ns, set, "key");
@Before
public void setUpRecord() {
Map<String, Object> binMap = new HashMap<>();
binMap.put("bin1", "val1");
testRecord = new Record(binMap, 1, 1);
}
@Test
public void testNoArgConstructor() {
new RestClientBatchReadResponse();
}
@Test
public void constructionWithBinNames() {
BatchRead nullRecordRead = getBatchRead(testKey, testBins, false, null);
RestClientBatchReadResponse response = new RestClientBatchReadResponse(nullRecordRead);
replacedert.replacedertArrayEquals(testBins, response.binNames);
replacedert.replacedertNull(response.record);
replacedert.replacedertFalse(response.readAllBins);
}
@Test
public void constructionWithoutBinNamesReadAllBins() {
BatchRead nullRecordRead = getBatchRead(testKey, null, true, null);
RestClientBatchReadResponse response = new RestClientBatchReadResponse(nullRecordRead);
replacedert.replacedertNull(response.binNames);
replacedert.replacedertNull(response.record);
replacedert.replacedertTrue(response.readAllBins);
}
@Test
public void constructionWithoutBinNamesReadAllBinsFalse() {
BatchRead nullRecordRead = getBatchRead(testKey, null, false, null);
RestClientBatchReadResponse response = new RestClientBatchReadResponse(nullRecordRead);
replacedert.replacedertNull(response.binNames);
replacedert.replacedertNull(response.record);
replacedert.replacedertFalse(response.readAllBins);
}
@Test
public void constructionOfUserKey() {
BatchRead nullRecordRead = getBatchRead(testKey, null, false, null);
RestClientBatchReadResponse response = new RestClientBatchReadResponse(nullRecordRead);
Key convertedKey = response.key.toKey();
replacedert.replacedertTrue(ASTestUtils.compareKeys(testKey, convertedKey));
}
@Test
public void constructionOfRecord() {
BatchRead nullRecordRead = getBatchRead(testKey, null, false, testRecord);
RestClientBatchReadResponse response = new RestClientBatchReadResponse(nullRecordRead);
RestClientRecord convertedRecord = response.record;
replacedert.replacedertEquals(convertedRecord.bins, testRecord.bins);
replacedert.replacedertEquals(convertedRecord.ttl, testRecord.getTimeToLive());
replacedert.replacedertEquals(convertedRecord.generation, testRecord.generation);
}
private BatchRead getBatchRead(Key key, String[] bins, boolean readAllbins, Record record) {
BatchRead read;
if (bins != null) {
read = new BatchRead(key, bins);
} else {
read = new BatchRead(key, readAllbins);
}
read.record = record;
return read;
}
}
18
Source : AerospikeKeyIterator.java
with Apache License 2.0
from Playtika
with Apache License 2.0
from Playtika
@Override
public void scanCallback(Key key, Record record) throws AerospikeException {
if (closed.get()) {
logger.info("AerospikeKeyIterator get closed, terminate scan");
throw new AerospikeException.ScanTerminated();
}
try {
queue.put(new KeyRecord(key, record));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
18
Source : AerospikeClient.java
with MIT License
from aliyun
with MIT License
from aliyun
@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
try {
Record record;
if (fields != null) {
record = client.get(readPolicy, new Key(namespace, table, key), fields.toArray(new String[fields.size()]));
} else {
record = client.get(readPolicy, new Key(namespace, table, key));
}
if (record == null) {
System.err.println("Record key " + key + " not found (read)");
return Status.ERROR;
}
for (Map.Entry<String, Object> entry : record.bins.entrySet()) {
result.put(entry.getKey(), new ByteArrayByteIterator((byte[]) entry.getValue()));
}
return Status.OK;
} catch (AerospikeException e) {
System.err.println("Error while reading key " + key + ": " + e);
return Status.ERROR;
}
}
18
Source : PreparedStatementWithComplexTypesTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
private <T> void replacedertInsertOneRowWithTypedKey(T id, Key key) throws SQLException {
PreparedStatement insert = testConn.prepareStatement("insert into people (PK, id, first_name, last_name) values (?, ?, ?, ?, ?)");
insert.setObject(1, id);
insert.setInt(2, 1);
insert.setString(3, "John");
insert.setString(4, "Lennon");
int rowCount = insert.executeUpdate();
replacedertEquals(1, rowCount);
Record record = getClient().get(null, key);
replacedertNotNull(record);
Map<String, Object> expectedData = new HashMap<>();
expectedData.put("id", 1L);
expectedData.put("first_name", "John");
expectedData.put("last_name", "Lennon");
replacedertEquals(expectedData, record.bins);
}
18
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
@Test
void insertBinaryStreams() throws SQLException {
Key key1 = new Key(NAMESPACE, DATA, 1);
replacedertNull(client.get(null, key1));
PreparedStatement ps = testConn.prepareStatement("insert into data (PK, bin_stream, bin_stream_i, bin_stream_l) values (?, ?, ?, ?)");
String text = "hello, binary stream!";
byte[] bytes = text.getBytes();
ps.setInt(1, 1);
ps.setBinaryStream(2, new ByteArrayInputStream(bytes));
ps.setBinaryStream(3, new ByteArrayInputStream(bytes), bytes.length);
ps.setBinaryStream(4, new ByteArrayInputStream(bytes), (long) bytes.length);
replacedertEquals(1, ps.executeUpdate());
Record record1 = client.get(null, key1);
replacedertNotNull(record1);
replacedertArrayEquals(bytes, (byte[]) record1.getValue("bin_stream"));
replacedertArrayEquals(bytes, (byte[]) record1.getValue("bin_stream_i"));
replacedertArrayEquals(bytes, (byte[]) record1.getValue("bin_stream_l"));
}
18
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
@Test
void insertBytes() throws SQLException {
Key key1 = new Key(NAMESPACE, DATA, 1);
replacedertNull(client.get(null, key1));
PreparedStatement ps = testConn.prepareStatement("insert into data (PK, bytes) values (?, ?)");
String text = "hello, blob!";
byte[] bytes = text.getBytes();
ps.setInt(1, 1);
ps.setBytes(2, bytes);
replacedertEquals(1, ps.executeUpdate());
Record record1 = client.get(null, key1);
replacedertNotNull(record1);
replacedertArrayEquals(bytes, (byte[]) record1.getValue("bytes"));
try (ResultSet rs = testConn.createStatement().executeQuery("select bytes from data")) {
replacedertTrue(rs.next());
replacedertArrayEquals(bytes, rs.getBytes("bytes"));
replacedertFalse(rs.next());
}
}
18
Source : MsgpackPost.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void testStoringByteArray() throws Exception {
Map<String, byte[]> byteBins = new HashMap<>();
byte[] testBytes = new byte[] { 1, 127, 127, 1 };
byteBins.put("byte", testBytes);
mockMVC.perform(post(testEndpoint).contentType(mtString).content(mapper.writeValueAsBytes(byteBins))).andExpect(status().isCreated());
Record rec = client.get(null, testKey);
byte[] realBytes = (byte[]) rec.bins.get("byte");
replacedert.replacedertArrayEquals(testBytes, realBytes);
}
18
Source : RestClientRecordTest.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void testWithBins() {
Map<String, Object> bins = new HashMap<>();
bins.put("bin1", 5l);
bins.put("bin2", "hello");
Record record = new Record(bins, 2, 1000);
RestClientRecord rcRecord = new RestClientRecord(record);
replacedert.replacedertEquals(rcRecord.bins, bins);
replacedert.replacedertEquals(rcRecord.generation, 2);
replacedert.replacedertEquals(rcRecord.ttl, record.getTimeToLive());
}
18
Source : BatchReadResponseTest.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
private BatchRead getBatchRead(Key key, String[] bins, boolean readAllbins, Record record) {
BatchRead read;
if (bins != null) {
read = new BatchRead(key, bins);
} else {
read = new BatchRead(key, readAllbins);
}
read.record = record;
return read;
}
18
Source : ASTestUtils.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@SuppressWarnings("unchecked")
public static /*
* Deep comparison of Map<String, Object>
*/
boolean compareRCRecordToASRecord(Map<String, Object> rcRecord, Record asRecord) {
Map<String, Object> map1 = (Map<String, Object>) rcRecord.get("bins");
Map<String, Object> map2 = asRecord.bins;
if (map1 == null || map2 == null)
return false;
if (map1.size() != map2.size())
return false;
for (String key : map1.keySet()) {
Object value1 = map1.get(key);
Object value2 = map2.get(key);
if (value1 instanceof byte[]) {
if (!Arrays.equals((byte[]) value1, (byte[]) value2)) {
return false;
}
} else if (value1 instanceof List) {
if (!compareCollection((List<?>) value1, (List<?>) value2)) {
return false;
}
} else if (value1 instanceof Map) {
if (!compareMap((Map<Object, Object>) value1, (Map<Object, Object>) value2)) {
return false;
}
} else if (!compareSimpleValues(value1, value2)) {
return false;
}
}
return true;
}
17
Source : EmbeddedAerospikeBootstrapConfigurationTest.java
with MIT License
from Playtika
with MIT License
from Playtika
@Test
public void shouldSave() throws Exception {
Key key = new Key(namespace, SET, "key1");
Bin bin = new Bin("mybin", "myvalue");
client.put(policy, key, bin);
Record actual = client.get(policy, key);
replacedertThat(actual.bins).hreplacedize(1);
replacedertThat(actual.bins.get("mybin")).isEqualTo("myvalue");
}
17
Source : PreparedStatementWithComplexTypesTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
private void replacedertOneInsertedRowUsingPreparedStatementWithDifferentKeyType(ThrowingConsumer<PreparedStatement, SQLException> setter, Key key) throws SQLException {
PreparedStatement insert = testConn.prepareStatement("insert into people (PK, id, first_name, last_name, kids) values (?, ?, ?, ?, ?)");
setter.accept(insert);
insert.setInt(2, 1);
insert.setString(3, "John");
insert.setString(4, "Lennon");
insert.setArray(5, testConn.createArrayOf("varchar", new String[] { "Sean", "Julian" }));
int rowCount = insert.executeUpdate();
replacedertEquals(1, rowCount);
Record record = getClient().get(null, key);
replacedertNotNull(record);
Map<String, Object> expectedData = new HashMap<>();
expectedData.put("id", 1L);
expectedData.put("first_name", "John");
expectedData.put("last_name", "Lennon");
expectedData.put("kids", asList("Sean", "Julian"));
replacedertEquals(expectedData, record.bins);
PreparedStatement select = testConn.prepareStatement("select id, first_name, last_name, kids from people where PK=?");
setter.accept(select);
ResultSet rs = select.executeQuery();
replacedertTrue(rs.next());
replacedertEquals(1, rs.getInt(1));
replacedertEquals(1, rs.getInt("id"));
replacedertThrows(SQLException.clreplaced, () -> rs.getAsciiStream(1));
replacedertThrows(SQLException.clreplaced, () -> rs.getAsciiStream("id"));
replacedertThrows(SQLException.clreplaced, () -> rs.getBinaryStream(1));
replacedertThrows(SQLException.clreplaced, () -> rs.getBinaryStream("id"));
replacedertThrows(SQLException.clreplaced, () -> rs.getCharacterStream(1));
replacedertThrows(SQLException.clreplaced, () -> rs.getCharacterStream("id"));
replacedertThrows(SQLException.clreplaced, () -> rs.getNCharacterStream(1));
replacedertThrows(SQLException.clreplaced, () -> rs.getNCharacterStream("id"));
replacedertEquals("John", rs.getString(2));
replacedertEquals("John", rs.getString("first_name"));
replacedertEquals("Lennon", rs.getString(3));
replacedertEquals("Lennon", rs.getString("last_name"));
List<String> expectedKids = asList("Sean", "Julian");
replacedertEquals(expectedKids, rs.getObject(4));
replacedertEquals(expectedKids, rs.getObject("kids"));
replacedertEquals(expectedKids, asList((Object[]) rs.getArray(4).getArray()));
replacedertEquals(expectedKids, asList((Object[]) rs.getArray("kids").getArray()));
ResultSet arrayRs = rs.getArray(4).getResultSet();
replacedertTrue(arrayRs.next());
replacedertEquals(1, arrayRs.getInt(1));
replacedertEquals("Sean", arrayRs.getString(2));
replacedertTrue(arrayRs.next());
replacedertEquals(2, arrayRs.getInt(1));
replacedertEquals("Julian", arrayRs.getString(2));
replacedertFalse(arrayRs.next());
replacedertFalse(rs.next());
}
17
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
@Test
void insertBlobs() throws SQLException, IOException {
Key key1 = new Key(NAMESPACE, DATA, 1);
replacedertNull(client.get(null, key1));
PreparedStatement ps = testConn.prepareStatement("insert into data (PK, blob, input_stream, limited_is) values (?, ?, ?, ?)");
String text = "hello, blob!";
byte[] bytes = text.getBytes();
Blob blob = new ByteArrayBlob();
blob.setBytes(1, text.getBytes());
ps.setInt(1, 1);
ps.setBlob(2, blob);
ps.setBlob(3, new ByteArrayInputStream(bytes));
ps.setBlob(4, new ByteArrayInputStream(bytes), bytes.length);
InputStream in1 = mock(InputStream.clreplaced);
when(in1.read(any(byte[].clreplaced), any(int.clreplaced), any(int.clreplaced))).thenThrow(EOFException.clreplaced);
replacedertThrows(SQLException.clreplaced, () -> ps.setBlob(4, in1, bytes.length));
InputStream in2 = mock(InputStream.clreplaced);
when(in2.read(any(byte[].clreplaced), any(int.clreplaced), any(int.clreplaced))).thenThrow(IOException.clreplaced);
replacedertThrows(SQLException.clreplaced, () -> ps.setBlob(4, in2, bytes.length));
replacedertEquals(1, ps.executeUpdate());
Record record1 = client.get(null, key1);
replacedertNotNull(record1);
replacedertArrayEquals(bytes, (byte[]) record1.getValue("blob"));
replacedertArrayEquals(bytes, (byte[]) record1.getValue("input_stream"));
replacedertArrayEquals(bytes, (byte[]) record1.getValue("limited_is"));
try (ResultSet rs = testConn.createStatement().executeQuery("select blob from data")) {
replacedertTrue(rs.next());
replacedertArrayEquals(bytes, rs.getBytes("blob"));
replacedertFalse(rs.next());
}
}
17
Source : InsertTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
private void insertOneRowUsingPreparedStatementVariousTypes(long now) throws SQLException, IOException {
Key key1 = new Key(NAMESPACE, DATA, 1);
replacedertNull(client.get(null, key1));
PreparedStatement ps = testConn.prepareStatement("insert into data (PK, byte, short, int, long, boolean, float_number, double_number, bigdecimal, string, nstring, blob, clob, nclob, t, ts, d, url, nothing) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
String helloWorld = "hello, world!";
String google = "http://www.google.com";
ps.setInt(1, 1);
ps.setByte(2, (byte) 8);
ps.setShort(3, (short) 512);
ps.setInt(4, 1024);
ps.setLong(5, now);
ps.setBoolean(6, true);
ps.setFloat(7, 3.14f);
ps.setDouble(8, 2.718281828);
ps.setBigDecimal(9, BigDecimal.valueOf(Math.PI));
ps.setString(10, "hello");
ps.setNString(11, helloWorld);
Blob blob = testConn.createBlob();
blob.setBytes(1, helloWorld.getBytes());
ps.setBlob(12, blob);
Clob clob = testConn.createClob();
clob.setString(1, helloWorld);
ps.setClob(13, clob);
NClob nclob = testConn.createNClob();
nclob.setString(1, helloWorld);
ps.setNClob(14, nclob);
ps.setTime(15, new Time(now));
ps.setTimestamp(16, new Timestamp(now));
ps.setDate(17, new java.sql.Date(now));
ps.setURL(18, new URL(google));
ps.setNull(19, Types.VARCHAR);
replacedertEquals(1, ps.executeUpdate());
Record record1 = client.get(null, key1);
replacedertNotNull(record1);
replacedertEquals(8, record1.getByte("byte"));
// work around on Aerospike client bug: getShort() fails on casting
replacedertEquals((short) 512, record1.getValue("short"));
replacedertEquals(1024, record1.getInt("int"));
replacedertEquals(now, record1.getLong("long"));
replacedertTrue(record1.getBoolean("boolean"));
replacedertEquals(3.14f, record1.getFloat("float_number"));
replacedertEquals(2.718281828, record1.getDouble("double_number"));
replacedertEquals(Math.PI, record1.getDouble("bigdecimal"));
replacedertEquals("hello", record1.getString("string"));
replacedertEquals(helloWorld, record1.getString("nstring"));
replacedertArrayEquals(helloWorld.getBytes(), (byte[]) record1.getValue("blob"));
replacedertEquals(helloWorld, record1.getString("clob"));
replacedertEquals(helloWorld, record1.getString("nclob"));
replacedertEquals(new Time(now), record1.getValue("t"));
replacedertEquals(new Timestamp(now), record1.getValue("ts"));
replacedertEquals(new java.sql.Date(now), record1.getValue("d"));
replacedertEquals(google, record1.getString("url"));
replacedertNull(record1.getString("nothing"));
}
17
Source : OperateTestCorrect.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void testGetHeaderOp() throws Exception {
List<Map<String, Object>> opList = new ArrayList<>();
Map<String, Object> opMap = new HashMap<>();
Map<String, Object> opValues = new HashMap<>();
opMap.put(OPERATION_FIELD, AerospikeOperation.GET_HEADER);
opMap.put(OPERATION_VALUES_FIELD, opValues);
opList.add(opMap);
String jsString = objectMapper.writeValuereplacedtring(opList);
String jsonResult = ASTestUtils.performOperationAndReturn(mockMVC, testEndpoint, jsString);
Map<String, Object> rcRecord = objectMapper.readValue(jsonResult, binType);
replacedert.replacedertNull(rcRecord.get(AerospikeAPIConstants.RECORD_BINS));
Record realRecord = client.getHeader(null, testKey);
int generation = (int) rcRecord.get(AerospikeAPIConstants.GENERATION);
replacedert.replacedertEquals(generation, realRecord.generation);
}
17
Source : OperateHLLTestsCorrect.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void testHLLAdd() {
createHLLBin("hll", values);
Record record = client.operate(null, testKey, HLLOperation.getCount("hll"));
long count = (long) record.bins.get("hll");
replacedert.replacedertEquals(7, count);
}
17
Source : OperateHLLTestsCorrect.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void testHLLRefreshCount() {
createHLLBin("hll", values);
List<Map<String, Object>> opList = new ArrayList<>();
Map<String, Object> opMap = new HashMap<>();
Map<String, Object> opValues = new HashMap<>();
opValues.put("bin", "hll");
opMap.put(OPERATION_FIELD, AerospikeOperation.HLL_SET_COUNT);
opMap.put(OPERATION_VALUES_FIELD, opValues);
opList.add(opMap);
opPerformer.performOperationsAndReturn(mockMVC, testEndpoint, opList);
Record record = client.operate(null, testKey, HLLOperation.getCount("hll"));
long count = (long) record.bins.get("hll");
replacedert.replacedertEquals(7, count);
}
17
Source : OperateHLLTestsCorrect.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void testHLLSetUnion() {
createHLLBin("hll", values);
createHLLBin("hll2", values2);
Value.HLLValue hll2Bin = (Value.HLLValue) client.get(null, testKey).bins.get("hll2");
List<Map<String, Object>> opList = new ArrayList<>();
Map<String, Object> opMap = new HashMap<>();
Map<String, Object> opValues = new HashMap<>();
opValues.put("bin", "hll");
opValues.put("values", Collections.singletonList(Base64.getEncoder().encodeToString(hll2Bin.getBytes())));
opMap.put(OPERATION_FIELD, AerospikeOperation.HLL_SET_UNION);
opMap.put(OPERATION_VALUES_FIELD, opValues);
opList.add(opMap);
opPerformer.performOperationsAndReturn(mockMVC, testEndpoint, opList);
Record record = client.operate(null, testKey, HLLOperation.getCount("hll"));
long count = (long) record.bins.get("hll");
replacedert.replacedertEquals(10, count);
}
17
Source : MsgpackPost.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void testStoringByteArray2() throws Exception {
byte[] testBytes = { 1, 2, 3 };
MessageBufferPacker packer = new MessagePack.PackerConfig().newBufferPacker();
packer.packMapHeader(1);
packer.packString("my_bytes");
packer.packBinaryHeader(3);
packer.writePayload(testBytes);
byte[] payload = packer.toByteArray();
mockMVC.perform(post(testEndpoint).contentType(mtString).content(payload)).andExpect(status().isCreated());
Record rec = client.get(null, testKey);
byte[] realBytes = (byte[]) rec.bins.get("my_bytes");
replacedert.replacedertArrayEquals(testBytes, realBytes);
}
17
Source : RestClientRecordTest.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void testNullBins() {
Record record = new Record(null, 2, 1000);
RestClientRecord rcRecord = new RestClientRecord(record);
replacedert.replacedertNull(rcRecord.bins);
replacedert.replacedertEquals(rcRecord.generation, 2);
replacedert.replacedertEquals(rcRecord.ttl, record.getTimeToLive());
}
16
Source : ReadOperations.java
with Apache License 2.0
from Playtika
with Apache License 2.0
from Playtika
public EntryList getSlice(String storeName, KeySliceQuery query) throws BackendException {
try {
Record record = aerospikeOperations.getClient().operate(getPolicy, aerospikeOperations.getKey(storeName, query.getKey()), MapOperation.getByKeyRange(ENTRIES_BIN_NAME, getValue(query.getSliceStart()), getValue(query.getSliceEnd()), MapReturnType.KEY_VALUE));
return recordToEntries(record, query.getLimit());
} catch (AerospikeException e) {
throw new PermanentBackendException(e);
}
}
16
Source : BatchExpectedValueOperations.java
with Apache License 2.0
from Playtika
with Apache License 2.0
from Playtika
private boolean checkColumnValues(final Key key, final Map<Value, Value> valuesForKey) {
if (valuesForKey.isEmpty()) {
return true;
}
int columnsNo = valuesForKey.size();
Value[] columns = new Value[columnsNo];
Operation[] operations = new Operation[columnsNo];
int i = 0;
for (Value column : valuesForKey.keySet()) {
columns[i] = column;
operations[i] = MapOperation.getByKey(ENTRIES_BIN_NAME, column, MapReturnType.VALUE);
i++;
}
try {
Record record = aerospikeOperations.getClient().operate(checkValuesPolicy, key, operations);
if (record != null) {
if (columnsNo > 1) {
List<?> resultList;
if ((resultList = record.getList(ENTRIES_BIN_NAME)) != null) {
for (int j = 0, n = resultList.size(); j < n; j++) {
Value column = columns[j];
if (!checkValue(key, column, valuesForKey.get(column), (byte[]) resultList.get(j))) {
return false;
}
}
}
return true;
} else {
// columnsNo == 1
byte[] actualValueData = (byte[]) record.getValue(ENTRIES_BIN_NAME);
Value column = columns[0];
return checkValue(key, column, valuesForKey.get(column), actualValueData);
}
} else {
return valuesForKey.values().stream().allMatch(value -> value.equals(Value.NULL));
}
} catch (Throwable throwable) {
logger.error("Error while checkColumnValues for key={}, values={}", key, valuesForKey, throwable);
throw throwable;
}
}
16
Source : OperateTestCorrect.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void testDeleteOp() throws Exception {
List<Map<String, Object>> opList = new ArrayList<>();
Map<String, Object> opMap = new HashMap<>();
Map<String, Object> opValues = new HashMap<>();
opMap.put(OPERATION_FIELD, AerospikeOperation.DELETE);
opMap.put(OPERATION_VALUES_FIELD, opValues);
opList.add(opMap);
String jsString = objectMapper.writeValuereplacedtring(opList);
ASTestUtils.performOperation(mockMVC, testEndpoint, jsString);
Record record = client.get(null, testKey);
replacedert.replacedertNull(record);
}
15
Source : ReadOperations.java
with Apache License 2.0
from Playtika
with Apache License 2.0
from Playtika
private EntryList recordToEntries(Record record, int entriesNo) {
List<?> resultList;
if (record != null && (resultList = record.getList(ENTRIES_BIN_NAME)) != null && !resultList.isEmpty()) {
final EntryArrayList result = new EntryArrayList();
resultList.stream().limit(entriesNo).forEach(o -> {
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
result.add(StaticArrayEntry.of(StaticArrayBuffer.of((byte[]) entry.getKey()), StaticArrayBuffer.of((byte[]) entry.getValue())));
});
return result;
} else {
return EntryList.EMPTY_LIST;
}
}
15
Source : DevTest.java
with Apache License 2.0
from alexradzin
with Apache License 2.0
from alexradzin
// @Test
void pk() {
WritePolicy wp = new WritePolicy();
wp.sendKey = true;
writeBeatles(wp);
ScanPolicy sp = new ScanPolicy();
// sp.sendKey = true;
client.screplacedl(null, "test", "people", new ScanCallback() {
@Override
public void scanCallback(Key key, Record record) throws AerospikeException {
System.out.printf("key=%s: record=%s\n", key, record);
}
});
Record rec1 = client.get(null, new Key("test", "people", 1));
System.out.println("rec: " + rec1);
Record[] recs = client.get(null, new Key[] { new Key("test", "people", 1), new Key("test", "people", 2) });
for (Record r : recs) {
System.out.println("rec: " + rec1);
}
Statement s = new Statement();
s.setSetName("people");
s.setNamespace("test");
for (KeyRecord kr : client.query(null, s)) {
System.out.printf("key= %s, rec=%s\n", kr.key, kr.record);
}
}
15
Source : TruncateTestsCorrect.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void TruncateWithCutoff() throws Exception {
mockMVC.perform(delete(testEndpoint + "test/truncate?date=" + truncateSplitPoint)).andExpect(status().isAccepted());
Thread.sleep(5000);
boolean preStillExists = false;
boolean postStillExists = true;
for (Key key : preCutoffKeys) {
Record record = client.get(null, key);
if (record != null) {
preStillExists = true;
break;
}
}
replacedert.replacedertFalse(preStillExists);
for (Key key : postCutoffKeys) {
Record record = client.get(null, key);
if (record == null) {
postStillExists = true;
break;
}
}
replacedert.replacedertTrue(postStillExists);
Record otherRecord = client.get(null, otherKey);
replacedert.replacedertNotNull(otherRecord);
}
15
Source : TruncateTestsCorrect.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void TruncateEntireNS() throws Exception {
mockMVC.perform(delete(testEndpoint + "test")).andExpect(status().isAccepted());
Thread.sleep(5000);
boolean stillExists = false;
for (Key key : preCutoffKeys) {
Record record = client.get(null, key);
if (record != null) {
stillExists = true;
break;
}
}
for (Key key : postCutoffKeys) {
Record record = client.get(null, key);
if (record != null) {
stillExists = true;
break;
}
}
replacedert.replacedertFalse(stillExists);
Record otherRecord = client.get(null, otherKey);
replacedert.replacedertNull(otherRecord);
}
15
Source : TruncateTestsCorrect.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void TruncateWithNoCutoff() throws Exception {
mockMVC.perform(delete(testEndpoint + "test/truncate")).andExpect(status().isAccepted());
Thread.sleep(5000);
boolean stillExists = false;
for (Key key : preCutoffKeys) {
Record record = client.get(null, key);
if (record != null) {
stillExists = true;
break;
}
}
for (Key key : postCutoffKeys) {
Record record = client.get(null, key);
if (record != null) {
stillExists = true;
break;
}
}
replacedert.replacedertFalse(stillExists);
Record otherRecord = client.get(null, otherKey);
replacedert.replacedertNotNull(otherRecord);
}
15
Source : RecordDeleteCorrectTests.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void DeleteRecordWithDigestKey() throws Exception {
mockMVC.perform(delete(digestEndpoint).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNoContent());
Record record = client.get(null, this.testKey);
replacedert.replacedertNull(record);
}
15
Source : RecordDeleteCorrectTests.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void DeleteRecordWithBytesKey() throws Exception {
mockMVC.perform(delete(bytesEndpoint).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNoContent());
Record record = client.get(null, this.bytesKey);
replacedert.replacedertNull(record);
}
15
Source : RecordDeleteCorrectTests.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void DeleteRecordWithGenerationMismatch() throws Exception {
String extraParams = "?generation=150&generationPolicy=EXPECT_GEN_EQUAL";
mockMVC.perform(delete(testEndpoint + extraParams).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isConflict());
Record record = client.get(null, this.testKey);
replacedert.replacedertNotNull(record);
}
15
Source : RecordDeleteCorrectTests.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void DeleteRecordWithIntKey() throws Exception {
mockMVC.perform(delete(intEndpoint).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNoContent());
Record record = client.get(null, this.intKey);
replacedert.replacedertNull(record);
}
15
Source : RecordDeleteCorrectTests.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void DeleteRecord() throws Exception {
mockMVC.perform(delete(testEndpoint).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNoContent());
Record record = client.get(null, this.testKey);
replacedert.replacedertNull(record);
}
15
Source : OperateTestCorrect.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void testTouchOpWithIntegerKey() throws Exception {
List<Map<String, Object>> opList = new ArrayList<>();
Map<String, Object> opMap = new HashMap<>();
Map<String, Object> opValues = new HashMap<>();
String intEndpoint = ASTestUtils.buildEndpoint("operate", "test", "junit", "1") + "?keytype=INTEGER";
Record record = client.get(null, intKey);
int oldGeneration = record.generation;
opMap.put(OPERATION_FIELD, AerospikeOperation.TOUCH);
opMap.put(OPERATION_VALUES_FIELD, opValues);
opList.add(opMap);
String jsString = objectMapper.writeValuereplacedtring(opList);
ASTestUtils.performOperation(mockMVC, intEndpoint, jsString);
record = client.get(null, intKey);
replacedert.replacedertEquals(oldGeneration + 1, record.generation);
}
15
Source : OperateTestCorrect.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void testTouchOp() throws Exception {
List<Map<String, Object>> opList = new ArrayList<>();
Map<String, Object> opMap = new HashMap<>();
Map<String, Object> opValues = new HashMap<>();
Record record = client.get(null, testKey);
int oldGeneration = record.generation;
opMap.put(OPERATION_FIELD, AerospikeOperation.TOUCH);
opMap.put(OPERATION_VALUES_FIELD, opValues);
opList.add(opMap);
String jsString = objectMapper.writeValuereplacedtring(opList);
ASTestUtils.performOperation(mockMVC, testEndpoint, jsString);
record = client.get(null, testKey);
replacedert.replacedertEquals(oldGeneration + 1, record.generation);
}
15
Source : OperateTestCorrect.java
with Apache License 2.0
from aerospike
with Apache License 2.0
from aerospike
@Test
public void testTouchOpWithBytesKey() throws Exception {
List<Map<String, Object>> opList = new ArrayList<>();
Map<String, Object> opMap = new HashMap<>();
Map<String, Object> opValues = new HashMap<>();
String urlBytes = Base64.getUrlEncoder().encodeToString((byte[]) bytesKey.userKey.getObject());
String bytesEndpoint = ASTestUtils.buildEndpoint("operate", "test", "junit", urlBytes) + "?keytype=BYTES";
Record record = client.get(null, bytesKey);
int oldGeneration = record.generation;
opMap.put(OPERATION_FIELD, AerospikeOperation.TOUCH);
opMap.put(OPERATION_VALUES_FIELD, opValues);
opList.add(opMap);
String jsString = objectMapper.writeValuereplacedtring(opList);
ASTestUtils.performOperation(mockMVC, bytesEndpoint, jsString);
record = client.get(null, bytesKey);
replacedert.replacedertEquals(oldGeneration + 1, record.generation);
}
See More Examples