hazelcast/hazelcast — pull request #2702 by lukasblu (2014-06-12 00:06:24+00:00)
Title: XmlConfigBuilder: Near cache in-memory format can not be configured through XML file

Hi,

configuring the near cache in-memory format through a XML file does not work.

The problem is that the near cache uses reflection to configure itself. While looking for the method to invoke, the wrong method is choosen in NearCacheConfig. There are two methods with the same name, but having different argument types. If the method with the wrong argument type is selected, it will not be invoked.

Those are the two methods in question:

```java
NearCacheConfig.setInMemoryFormat(InMemoryFormat)
NearCacheConfig.setInMemoryFormat(String)
```

This pull request fixes the problem and the code below shows how to reproduce the issue.

Cheers,
Lukas

```java
package com.nm.test.hazelcast.config;

import com.hazelcast.config.*;
import com.nm.test.hazelcast.TestHazelcast;
import org.apache.log4j.BasicConfigurator;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import junit.framework.TestCase;

/**
* A test to ensure near-cache in-memory-format can be set through XML config.
*/
public class TestConfig1 extends TestCase {

@Override
protected void setUp() throws Exception {

// configure logging
if (!TestHazelcast.loggingInitialized) {
TestHazelcast.loggingInitialized = true;
BasicConfigurator.configure();
}
}

public void testNearCacheConfig() throws Exception {

// configure Log4j logging
System.setProperty("hazelcast.logging.type", "log4j");

// prepare config file
String configPath = "/tmp/hazelcast-test-config1.xml";
InputStream in = this.getClass().getResourceAsStream("hazelcast-test-config1.xml");
OutputStream out = new BufferedOutputStream(new FileOutputStream(configPath));
int next = -1;
while ((next = in.read()) != -1) {
out.write(next);
}
in.close();
out.close();
System.setProperty("hazelcast.config", configPath);

// create hazelcast config
Config config = new XmlConfigBuilder().build();

// test near-cache in-memory-format setting
MapConfig mapConfig = config.getMapConfig("testMapConfig1");
NearCacheConfig ncConfig = mapConfig.getNearCacheConfig();
if (!ncConfig.getInMemoryFormat().equals(InMemoryFormat.OBJECT)) {
fail("Near cache config in-memory-format not set.");
}
}

}
```

and the test config file:

```

dev
dev-pass

http://localhost:8080/mancenter

5701

0

224.2.2.3
54327

127.0.0.1

10.10.1.*

8
0

OBJECT

```