コード例 #1
0
  @Test(timeout = 120000)
  public void testIssue1115EnablingMapstoreMutatingValue() throws InterruptedException {
    Config config = getConfig();
    String mapName = "testIssue1115";
    MapStore mapStore = new ProcessingStore();
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(mapStore);
    config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    IMap<Integer, Employee> map = instance1.getMap(mapName);
    Random random = new Random();
    // testing put with new object
    for (int i = 0; i < 10; i++) {
      Employee emp = new Employee();
      emp.setAge(random.nextInt(20) + 20);
      map.put(i, emp);
    }

    for (int i = 0; i < 10; i++) {
      Employee employee = map.get(i);
      assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }

    // testing put with existing object
    for (int i = 0; i < 10; i++) {
      Employee emp = map.get(i);
      emp.setAge(random.nextInt(20) + 20);
      map.put(i, emp);
    }

    for (int i = 0; i < 10; i++) {
      Employee employee = map.get(i);
      assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }

    // testing put with replace
    for (int i = 0; i < 10; i++) {
      Employee emp = map.get(i);
      emp.setAge(random.nextInt(20) + 20);
      map.replace(i, emp);
    }

    for (int i = 0; i < 10; i++) {
      Employee employee = map.get(i);
      assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }

    // testing put with putIfAbsent
    for (int i = 10; i < 20; i++) {
      Employee emp = new Employee();
      emp.setAge(random.nextInt(20) + 20);
      map.putIfAbsent(i, emp);
    }

    for (int i = 10; i < 20; i++) {
      Employee employee = map.get(i);
      assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }
  }
コード例 #2
0
 @Override
 public void store(Integer key, Employee employee) {
   employee.setSalary(employee.getAge() * 1000);
 }