1717
1818package org .apache .ignite .cache .query ;
1919
20+ import java .util .List ;
2021import java .util .Objects ;
22+ import javax .cache .Cache ;
2123import org .apache .ignite .Ignite ;
2224import org .apache .ignite .IgniteCache ;
2325import org .apache .ignite .IgniteDataStreamer ;
2426import org .apache .ignite .IgniteException ;
27+ import org .apache .ignite .binary .BinaryObject ;
2528import org .apache .ignite .cache .CacheMode ;
2629import org .apache .ignite .cache .query .annotations .QuerySqlField ;
2730import org .apache .ignite .configuration .CacheConfiguration ;
@@ -99,6 +102,51 @@ public void testServerNodePartitionedCache() {
99102 assertEquals (CNT / 2 , resultSize );
100103 }
101104
105+ /** Should return deserialized values for a cache that is not in keep-binary mode. */
106+ @ Test
107+ public void testLocalQueryReturnsDeserializedValues () {
108+ IgniteCache <PersonId , Person > cache = crd .createCache (ccfgObjectKey (CacheMode .REPLICATED ));
109+
110+ insertDataWithPersonIdKey (crd , cache );
111+
112+ IndexQuery <PersonId , Person > qry = new IndexQuery <PersonId , Person >(Person .class , IDX )
113+ .setCriteria (lt ("id" , CNT / 2 ));
114+
115+ List <Cache .Entry <PersonId , Person >> res = cache .query (qry .setLocal (true )).getAll ();
116+
117+ for (Cache .Entry <PersonId , Person > e : res ) {
118+ assertEquals (new PersonId (e .getValue ().id ), e .getKey ());
119+ assertEquals (new Person (e .getKey ().id ), e .getValue ());
120+ }
121+
122+ assertEquals (CNT / 2 , res .size ());
123+ }
124+
125+ /** Should keep binary keys and values for a cache in keep-binary mode. */
126+ @ Test
127+ public void testLocalQueryKeepBinaryReturnsBinaryValues () {
128+ IgniteCache <PersonId , Person > cache = crd .createCache (ccfgObjectKey (CacheMode .REPLICATED ));
129+
130+ insertDataWithPersonIdKey (crd , cache );
131+
132+ IgniteCache <BinaryObject , BinaryObject > binCache = cache .withKeepBinary ();
133+
134+ IndexQuery <BinaryObject , BinaryObject > qry = new IndexQuery <BinaryObject , BinaryObject >(Person .class , IDX )
135+ .setCriteria (lt ("id" , CNT / 2 ));
136+
137+ List <Cache .Entry <BinaryObject , BinaryObject >> res = binCache .query (qry .setLocal (true )).getAll ();
138+
139+ for (Cache .Entry <BinaryObject , BinaryObject > e : res ) {
140+ PersonId key = e .getKey ().deserialize ();
141+ Person val = e .getValue ().deserialize ();
142+
143+ assertEquals (new PersonId (val .id ), key );
144+ assertEquals (new Person (key .id ), val );
145+ }
146+
147+ assertEquals (CNT / 2 , res .size ());
148+ }
149+
102150 /** Should fail as no data on nodes. */
103151 @ Test
104152 public void testClientNodeReplicatedCache () throws Exception {
@@ -136,6 +184,14 @@ private void insertData(Ignite ignite, IgniteCache<Long, Person> cache) {
136184 }
137185 }
138186
187+ /** */
188+ private void insertDataWithPersonIdKey (Ignite ignite , IgniteCache <PersonId , Person > cache ) {
189+ try (IgniteDataStreamer <PersonId , Person > streamer = ignite .dataStreamer (cache .getName ())) {
190+ for (int i = 0 ; i < CNT ; i ++)
191+ streamer .addData (new PersonId (i ), new Person (i ));
192+ }
193+ }
194+
139195 /** */
140196 private CacheConfiguration <Long , Person > ccfg (CacheMode cacheMode ) {
141197 return new CacheConfiguration <Long , Person >()
@@ -145,6 +201,15 @@ private CacheConfiguration<Long, Person> ccfg(CacheMode cacheMode) {
145201 .setBackups (2 );
146202 }
147203
204+ /** */
205+ private CacheConfiguration <PersonId , Person > ccfgObjectKey (CacheMode cacheMode ) {
206+ return new CacheConfiguration <PersonId , Person >()
207+ .setName (CACHE )
208+ .setIndexedTypes (PersonId .class , Person .class )
209+ .setCacheMode (cacheMode )
210+ .setBackups (2 );
211+ }
212+
148213 /** */
149214 private static class Person {
150215 /** */
@@ -178,4 +243,37 @@ private static class Person {
178243 return Objects .hash (id );
179244 }
180245 }
246+
247+ /** */
248+ private static class PersonId {
249+ /** */
250+ final int id ;
251+
252+ /** */
253+ PersonId (int id ) {
254+ this .id = id ;
255+ }
256+
257+ /** {@inheritDoc} */
258+ @ Override public String toString () {
259+ return "PersonId[id=" + id + "]" ;
260+ }
261+
262+ /** {@inheritDoc} */
263+ @ Override public boolean equals (Object o ) {
264+ if (this == o )
265+ return true ;
266+ if (o == null || getClass () != o .getClass ())
267+ return false ;
268+
269+ PersonId personId = (PersonId )o ;
270+
271+ return Objects .equals (id , personId .id );
272+ }
273+
274+ /** {@inheritDoc} */
275+ @ Override public int hashCode () {
276+ return Objects .hash (id );
277+ }
278+ }
181279}
0 commit comments