/hazelcast-client/src/test/java/com/hazelcast/client/HazelcastClientIdGeneratorTest.java

https://bitbucket.org/gabral6_gmailcom/hazelcast · Java · 53 lines · 30 code · 6 blank · 17 comment · 2 complexity · 60cd098c1f7d18d1e06a90478b1730b5 MD5 · raw file

  1. /*
  2. * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.hazelcast.client;
  17. import com.hazelcast.core.HazelcastInstance;
  18. import com.hazelcast.core.IdGenerator;
  19. import org.junit.Test;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import static junit.framework.Assert.assertTrue;
  23. import static org.junit.Assert.assertNull;
  24. public class HazelcastClientIdGeneratorTest extends HazelcastClientTestBase {
  25. @Test
  26. public void idGenerator() {
  27. HazelcastClient hClient = getHazelcastClient();
  28. HazelcastInstance h = getHazelcastInstance();
  29. IdGenerator nativeId = h.getIdGenerator("id");
  30. IdGenerator clientId = hClient.getIdGenerator("id");
  31. long v = clientId.newId();
  32. Map<Long, Integer> map = new HashMap<Long, Integer>();
  33. int count = 10;
  34. for (int i = 0; i < count; i++) {
  35. long genId = nativeId.newId();
  36. assertNull(map.put(genId, 1));
  37. // System.out.println(genId);
  38. }
  39. System.out.println(v);
  40. for (int i = 0; i < count; i++) {
  41. long genId = clientId.newId();
  42. assertNull(map.put(genId, 1));
  43. // System.out.println(genId);
  44. }
  45. assertTrue(true);
  46. }
  47. }