Skip to content

Commit

Permalink
Merge pull request #8172 from tombujok/portables-pr-backport
Browse files Browse the repository at this point in the history
Collection querying in Portables (squashed) - backport
  • Loading branch information
jerrinot committed May 16, 2016
2 parents 6952443 + c7b0adc commit 361f2d6
Show file tree
Hide file tree
Showing 59 changed files with 7,514 additions and 675 deletions.
Expand Up @@ -25,7 +25,6 @@
import com.hazelcast.core.EntryEvent;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.core.MapEvent;
import com.hazelcast.query.Predicate;
import com.hazelcast.query.Predicates;
import com.hazelcast.test.HazelcastSerialClassRunner;
Expand All @@ -39,10 +38,12 @@

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CountDownLatch;

import static com.hazelcast.query.Predicates.*;
import static com.hazelcast.query.Predicates.equal;
import static com.hazelcast.test.HazelcastTestSupport.assertOpenEventually;
import static com.hazelcast.test.HazelcastTestSupport.randomString;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -203,6 +204,9 @@ public void onEntryEvent(EntryEvent<Integer, MyPortableElement> event) {
}, predicate, true);
map.put(key, element);
assertOpenEventually(eventLatch);

Collection values = map.values(Predicates.lessThan("date", new Date().getTime()));
assertEquals(values.iterator().next(), element);
}

}
Expand Up @@ -12,12 +12,14 @@ public class MyPortableElement implements Portable {
public static final int CLASS_ID = 1;

private int id;
private Long date;

private MyPortableElement() {
}

public MyPortableElement(int id) {
this.id = id;
this.date = 123L;
}

@Override
Expand All @@ -33,11 +35,32 @@ public int getClassId() {
@Override
public void writePortable(PortableWriter writer) throws IOException {
writer.writeInt("id", id);
writer.writeLong("date", date);
}

@Override
public void readPortable(PortableReader reader) throws IOException {
id = reader.readInt("id");
date = reader.readLong("date");
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

MyPortableElement that = (MyPortableElement) o;

if (id != that.id) return false;
return date != null ? date.equals(that.date) : that.date == null;

}

@Override
public int hashCode() {
int result = id;
result = 31 * result + (date != null ? date.hashCode() : 0);
return result;
}

public static class Factory implements PortableFactory {
Expand Down

0 comments on commit 361f2d6

Please sign in to comment.