Hazelcast IList does not honour List behaviour (ordering, methods)

388 views
Skip to first unread message

häxx

unread,
Feb 9, 2011, 11:22:18 AM2/9/11
to Hazelcast
Hello folks.

I am concerned that I am missing something rather basic.
When getting a distributed List from Hazelcast, similar to the code
samples shown on the wiki and hazelcast.com sites, the behaviour
differs from the expected behaviour of java.util.Lists.

This seems very basic, but I can't see that I'm doing anything wrong.
Attaching a small testcase which fails in two ways:

a) The ordering of the elements in IList does not match the expected
{1, 2, 3}. Instead, the elements are unordered, similar to an ISet
implementation.
b) The List.get() method calls throw exceptions (more specifically
java.lang.UnsupportedOperationException
at com.hazelcast.impl.BaseCollection.get(BaseCollection.java:36))

What am I missing here?

@Test
public void validateOrderingInDistributedList() {

// Assemble
final HazelcastInstance cacheNode =
Hazelcast.newHazelcastInstance(HazelcastCache.readConfigFile(configFile));
final List<String> unitUnderTest =
cacheNode.getList("testList");

// Act
unitUnderTest.add("1");
unitUnderTest.add("2");
unitUnderTest.add("3");

// Assert
Assert.assertEquals(3, unitUnderTest.size());
Assert.assertEquals("1", unitUnderTest.get(0));
Assert.assertEquals("2", unitUnderTest.get(1));
Assert.assertEquals("3", unitUnderTest.get(2));
}

Fuad Malikov

unread,
Feb 9, 2011, 12:11:40 PM2/9/11
to haze...@googlegroups.com
Hi,

Hazelcast List does not preserve order. This is basically for performance reasons. It is very costly to order the items.
May be we should have documented this much better.

Fuad



--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To post to this group, send email to haze...@googlegroups.com.
To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hazelcast?hl=en.




--

@fuadm

Andy Burgess

unread,
Feb 10, 2011, 5:28:56 AM2/10/11
to haze...@googlegroups.com
.... or, more appropriately perhaps, what Hazelcast calls a List shouldn't implement the List interface. In my opinion, the Hazelcast.getList(...) method should instead be Hazelcast.getBag(...) or Hazelcast.getMultiSet(...) and the returned type should directly implement the Collection interface. See http://download.oracle.com/javase/1.4.2/docs/api/java/util/Collection.html

As an aside, surely you could implement a proper ordered List, no matter how costly, because aren't you currently doing just that for Queue? As long as it's documented as costly, the choice of whether or not to use it would rest with the end-user.

Comments?

Regards,
Andy.
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

-- 
Andy Burgess
Principal Development Engineer
Application Delivery
WorldPay Ltd.
270-289 Science Park, Milton Road
Cambridge, CB4 0WE, United Kingdom (Depot Code: 024)
Office: +44 (0)1223 706 779| Mobile: +44 (0)7909 534 940
andy.b...@worldpay.com

Talip Ozturk

unread,
Feb 10, 2011, 5:50:28 AM2/10/11
to haze...@googlegroups.com
Nice feedback. Makes sense. We cannot jump in and change things right
now but we should address this issue in the future.

http://twitter.com/oztalip

häxx

unread,
Feb 10, 2011, 10:02:32 AM2/10/11
to Hazelcast
Hello all,

I believe we should do one of 2 things:

a) Implement the java.util.List - including its behaviours - fully. If
the implementation implies a performance hit - document it clearly so
people can decide for themselves.
b) Drop the java.util.List interface from the IList implementation,
and move to Collection instead.

Personally, I would prefer the former choice.
I also believe we can implement the list interface on top of a Queue
implementation, since that implementation does not use a Map under the
covers. It seems that Queue elements *are* ordered, judging from the
implementation.

Talip Ozturk

unread,
Feb 10, 2011, 5:06:53 PM2/10/11
to haze...@googlegroups.com
Yes. Very possible. Queue is ordered.

http://twitter.com/oztalip

Dan Syrstad

unread,
Jan 25, 2013, 7:33:35 PM1/25/13
to haze...@googlegroups.com, ta...@hazelcast.com
I just ran into this too in Hazelcast 2.5. IQueue.iterator() has the same ordering problem. It seems that this has not been addressed yet. Any updates?
-Dan

darri...@bifrostengine.com

unread,
Feb 2, 2016, 3:48:26 AM2/2/16
to Hazelcast, lennart...@gmail.com
Recent documentation claims and testing shows order is preserved: http://docs.hazelcast.org/docs/3.5/manual/html/list.html. I let this old post mislead me for awhile, so I thought I'd leave a breadcrumb for the next person.

Peter Veentjer

unread,
Feb 2, 2016, 11:13:46 PM2/2/16
to haze...@googlegroups.com, lennart...@gmail.com
Correct. Hazelcast 3 IList has been completely rewritten. Ordering is preserved.

On Tue, Feb 2, 2016 at 1:54 AM, <darri...@bifrostengine.com> wrote:
Recent documentation claims and testing shows order is preserved: http://docs.hazelcast.org/docs/3.5/manual/html/list.html. I let this old post mislead me for awhile, so I thought I'd leave a breadcrumb for the next person.

--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.

To post to this group, send email to haze...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages