DATACOUCH-159 - Improved performance of decoding of longs.
Original pull requests: #67. Cherry-pick ofe5bed8e, adapted with polishing from6fec488.
This commit is contained in:
@@ -31,6 +31,7 @@ import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.couchbase.client.java.Bucket;
|
||||
import com.couchbase.client.java.document.RawJsonDocument;
|
||||
@@ -59,7 +60,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Michael Nitschinger
|
||||
*/
|
||||
* @author Simon Baslé
|
||||
* @author Anastasiia Smirnova */
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
|
||||
@TestExecutionListeners(CouchbaseTemplateViewListener.class)
|
||||
@@ -251,14 +253,25 @@ public class CouchbaseTemplateTests {
|
||||
assertEquals("test2", fragments.get(0).value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACOUCH-159
|
||||
*/
|
||||
@Test
|
||||
public void shouldDeserialiseLongs() {
|
||||
final long time = new Date().getTime();
|
||||
SimpleWithLong simpleWithLong = new SimpleWithLong("simpleWithLong:simple", time);
|
||||
template.save(simpleWithLong);
|
||||
simpleWithLong = template.findById("simpleWithLong:simple", SimpleWithLong.class);
|
||||
assertNotNull(simpleWithLong);
|
||||
assertEquals(time, simpleWithLong.getValue());
|
||||
public void shouldDeserialiseLongsAndInts() {
|
||||
final long longValue = new Date().getTime();
|
||||
final int intValue = new Random().nextInt();
|
||||
|
||||
template.save(new SimpleWithLongAndInt("simpleWithLong:simple", longValue, intValue));
|
||||
SimpleWithLongAndInt document = template.findById("simpleWithLong:simple", SimpleWithLongAndInt.class);
|
||||
assertNotNull(document);
|
||||
assertEquals(longValue, document.getLongValue());
|
||||
assertEquals(intValue, document.getIntValue());
|
||||
|
||||
template.save(new SimpleWithLongAndInt("simpleWithLong:simple:other", intValue, intValue));
|
||||
document = template.findById("simpleWithLong:simple:other", SimpleWithLongAndInt.class);
|
||||
assertNotNull(document);
|
||||
assertEquals(intValue, document.getLongValue());
|
||||
assertEquals(intValue, document.getIntValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -463,28 +476,38 @@ public class CouchbaseTemplateTests {
|
||||
}
|
||||
|
||||
@Document
|
||||
static class SimpleWithLong {
|
||||
static class SimpleWithLongAndInt {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private long value;
|
||||
private long longValue;
|
||||
private int intValue;
|
||||
|
||||
SimpleWithLong(final String id, final long value) {
|
||||
SimpleWithLongAndInt(final String id, final long longValue, int intValue) {
|
||||
this.id = id;
|
||||
this.value = value;
|
||||
this.longValue = longValue;
|
||||
this.intValue = intValue;
|
||||
}
|
||||
|
||||
String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
long getValue() {
|
||||
return value;
|
||||
long getLongValue() {
|
||||
return longValue;
|
||||
}
|
||||
|
||||
void setValue(final long value) {
|
||||
this.value = value;
|
||||
void setLongValue(final long value) {
|
||||
this.longValue = value;
|
||||
}
|
||||
|
||||
public int getIntValue() {
|
||||
return intValue;
|
||||
}
|
||||
|
||||
public void setIntValue(int intValue) {
|
||||
this.intValue = intValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user