/hazelcast/src/test/java/com/hazelcast/core/MultiMapPerformance.java

https://bitbucket.org/gabral6_gmailcom/hazelcast · Java · 101 lines · 74 code · 12 blank · 15 comment · 8 complexity · fdff4439142d6e38bc9cb568858f3d6a 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.core;
  17. import org.junit.After;
  18. import org.junit.Test;
  19. import org.junit.runner.RunWith;
  20. import java.util.Collection;
  21. import static org.junit.Assert.assertEquals;
  22. @RunWith(com.hazelcast.util.RandomBlockJUnit4ClassRunner.class)
  23. public class MultiMapPerformance extends PerformanceTest {
  24. private MultiMap<String, String> map = Hazelcast.getMultiMap("MultiMapPerformance");
  25. @After
  26. public void clear() {
  27. t.stop();
  28. t.printResult();
  29. map.clear();
  30. assertEquals(0, map.size());
  31. }
  32. @Test
  33. public void testMultiMapPutWithSameKeyAndValue() {
  34. String test = "testMultiMapPutWithSameKeyAndValue";
  35. t = new PerformanceTimer(test, ops);
  36. for (int i = 0; i < ops; ++i) {
  37. map.put("Hello", "World");
  38. }
  39. }
  40. @Test
  41. public void testMultiMapPutWithSameKeyAndDifferentValue() {
  42. String test = "testMultiMapPutWithSameKeyAndDifferentValue";
  43. ops /= 100;
  44. t = new PerformanceTimer(test, ops);
  45. for (int i = 0; i < ops; ++i) {
  46. map.put("Hello", "World" + i);
  47. }
  48. ops *= 100;
  49. }
  50. @Test
  51. public void testMultiMapPutWithDifferentKey() {
  52. String test = "testMultiMapPutWithDifferentKey";
  53. t = new PerformanceTimer(test, ops);
  54. for (int i = 0; i < ops; ++i) {
  55. map.put("Hello" + i, "World");
  56. }
  57. }
  58. @Test
  59. public void testMultiMapValues() {
  60. String test = "testMultiMapValues";
  61. for (int i = 0; i < ops; ++i) {
  62. map.put("Hello" + i, "World");
  63. }
  64. t = new PerformanceTimer(test, ops);
  65. Collection<String> values = map.values();
  66. }
  67. @Test
  68. public void testMultiMapGet() {
  69. String test = "testMultiMapGet";
  70. for (int i = 0; i < ops; ++i) {
  71. map.put("Hello" + i, "World");
  72. }
  73. t = new PerformanceTimer(test, ops);
  74. for (int i = 0; i < ops; ++i) {
  75. Collection<String> values = map.get("Hello" + i);
  76. }
  77. }
  78. @Test
  79. public void testMultiMapValueCount() {
  80. String test = "testMultiMapGet";
  81. for (int i = 0; i < ops; ++i) {
  82. map.put("Hello" + i, "World");
  83. }
  84. t = new PerformanceTimer(test, ops);
  85. for (int i = 0; i < ops; ++i) {
  86. int count = map.valueCount("Hello" + i);
  87. }
  88. }
  89. }