Skip to content

Commit

Permalink
Merge pull request #825: [proxima-tools] fix console.put contract
Browse files Browse the repository at this point in the history
  • Loading branch information
je-ik authored Aug 16, 2023
2 parents 0f682df + 49104ad commit 2d5edad
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions tools/src/main/java/cz/o2/proxima/tools/groovy/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void put(
AttributeDescriptor<?> attrDesc,
String key,
String attribute,
Object value)
String value)
throws InterruptedException {

put(entityDesc, attrDesc, key, attribute, System.currentTimeMillis(), value);
Expand All @@ -319,7 +319,7 @@ public void put(
String key,
String attribute,
long stamp,
Object value)
String value)
throws InterruptedException {

Preconditions.checkState(
Expand All @@ -328,7 +328,7 @@ public void put(
@SuppressWarnings("unchecked")
ValueSerializer<Object> valueSerializer =
(ValueSerializer<Object>) attrDesc.getValueSerializer();
byte[] payload = valueSerializer.serialize(valueSerializer.fromJsonValue(value.toString()));
byte[] payload = valueSerializer.serialize(valueSerializer.fromJsonValue(value));
OnlineAttributeWriter writer = Optionals.get(direct.getWriter(attrDesc));
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<Throwable> exc = new AtomicReference<>();
Expand Down
16 changes: 8 additions & 8 deletions tools/src/main/resources/class-entitydesc.ftlh
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ class Environment implements RepositoryProvider {
def List<KeyValue<${attribute.type}>> listPrefix(String key, String prefix) {
return ${entity.classname}Descriptor.this.reader.list(key, desc.toAttributePrefix() + prefix)
}
def void put(String key, String attribute, ${attribute.type} value) {
console.put(${entity.classname}Descriptor.this.desc, desc, key, desc.toAttributePrefix() + attribute, value)
def void put(String key, String attribute, String jsonValue) {
console.put(${entity.classname}Descriptor.this.desc, desc, key, desc.toAttributePrefix() + attribute, jsonValue)
}
def void put(String key, String attribute, long stamp, ${attribute.type} value) {
console.put(${entity.classname}Descriptor.this.desc, desc, key, desc.toAttributePrefix() + attribute, stamp, value)
def void put(String key, String attribute, long stamp, String jsonValue) {
console.put(${entity.classname}Descriptor.this.desc, desc, key, desc.toAttributePrefix() + attribute, stamp, jsonValue)
}
def void delete(String key, String attribute) {
console.delete(${entity.classname}Descriptor.this.desc, desc, key, desc.toAttributePrefix() + attribute)
Expand All @@ -157,11 +157,11 @@ class Environment implements RepositoryProvider {
def KeyValue<${attribute.type}> get(String key) {
return ${entity.classname}Descriptor.this.reader.get(key, name)
}
def void put(String key, ${attribute.type} value) {
console.put(${entity.classname}Descriptor.this.desc, desc, key, desc.getName(), value)
def void put(String key, String jsonValue) {
console.put(${entity.classname}Descriptor.this.desc, desc, key, desc.getName(), jsonValue)
}
def void put(String key, long stamp, ${attribute.type} value) {
console.put(${entity.classname}Descriptor.this.desc, desc, key, desc.getName(), stamp, value)
def void put(String key, long stamp, String jsonValue) {
console.put(${entity.classname}Descriptor.this.desc, desc, key, desc.getName(), stamp, jsonValue)
}
def void delete(String key) {
console.delete(${entity.classname}Descriptor.this.desc, desc, key, desc.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
package cz.o2.proxima.tools.groovy.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;

import cz.o2.proxima.core.repository.AttributeDescriptor;
import cz.o2.proxima.core.repository.EntityDescriptor;
Expand All @@ -43,7 +42,7 @@ public class ConsoleRandomReaderTest {

@Test(timeout = 10000)
public void testConsoleRandomReaderRead() throws InterruptedException {
console.put(proxied, ints, "key", "ints.1", 1);
console.put(proxied, ints, "key", "ints.1", "1");
KeyValue<Integer> result =
console.getRandomAccessReader(proxied.getName()).get("key", "ints.1");
assertNotNull(result.getValue());
Expand All @@ -60,4 +59,11 @@ public void testConsoleRandomReaderRead() throws InterruptedException {
Collections.singletonList("key"),
keys.stream().map(Pair::getSecond).collect(Collectors.toList()));
}

@Test
public void testConsolePut() throws InterruptedException {
console.put(proxied, ints, "key", "ints.1", "1");
assertThrows(
NumberFormatException.class, () -> console.put(proxied, ints, "key", "ints.2", "\"2\""));
}
}

0 comments on commit 2d5edad

Please sign in to comment.