Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BackupEntryProcessor returned from AbstractEntryProcessor does not support HazelcastInstanceAware #10083

Closed
mmedenjak opened this issue Mar 15, 2017 · 0 comments

Comments

@mmedenjak
Copy link
Contributor

@mmedenjak mmedenjak commented Mar 15, 2017

If the backup entry processor implements HazelcastInstanceAware, the instance is not injected.
Reproducer:

@RunWith(HazelcastSerialClassRunner.class)
@Category({QuickTest.class, ParallelTest.class})
public class BackupEntryProcessorInstanceAware extends HazelcastTestSupport {

    public static final String MAP_NAME = "EntryProcessorTest";

    @Override
    public Config getConfig() {
        Config config = super.getConfig();
        MapConfig mapConfig = new MapConfig(MAP_NAME);
        mapConfig.setInMemoryFormat(BINARY);
        config.addMapConfig(mapConfig);
        return config;
    }


    @Test
    public void test() {
        final Config cfg = getConfig();
        final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
        final HazelcastInstance i1 = factory.newHazelcastInstance(cfg);
        final HazelcastInstance i2 = factory.newHazelcastInstance(cfg);

        try {
            final IMap<Object, Object> map = i1.getMap(MAP_NAME);
            map.put("a", 1);
            map.put("b", 2);
            map.executeOnEntries(new PartitionAwareTestEntryProcessor(MAP_NAME));
        } catch (ClassCastException e) {
            e.printStackTrace();
            fail("ClassCastException must not happen!");
        } finally {
            i1.shutdown();
        }
    }


    private static class PartitionAwareTestEntryProcessor extends AbstractEntryProcessor<Object, Object>
            implements HazelcastInstanceAware {

        private String name;
        private transient HazelcastInstance hz;

        private PartitionAwareTestEntryProcessor(String name) {
            this.name = name;
        }

        @Override
        public Object process(Map.Entry<Object, Object> entry) {
            hz.getMap(name).put(entry.getKey(), entry.getValue());
            return null;
        }

        @Override
        public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
            this.hz = hazelcastInstance;
        }
    }

}
@mmedenjak mmedenjak added this to the 3.8.1 milestone Mar 15, 2017
@mmedenjak mmedenjak self-assigned this Mar 15, 2017
@mmedenjak mmedenjak changed the title BackupEntryProcessor does not support HazelcastInstanceAware BackupEntryProcessor returned from AbstractEntryProcessor does not support HazelcastInstanceAware Mar 15, 2017
mmedenjak added a commit to mmedenjak/hazelcast that referenced this issue Mar 15, 2017
If the supplied entry procesor extended AbstractEntryProcessor and implemented HazelcastInstanceAware, the backup processor would never get the hazelcast instance injected and the process method could fail with NPE. The fix checks if the entry processor implements HazelcastInstanceAware and supplies a different backup processor in that case.

Fixes : hazelcast#10083
mmedenjak added a commit to mmedenjak/hazelcast that referenced this issue Mar 15, 2017
If the supplied entry procesor extended AbstractEntryProcessor and implemented HazelcastInstanceAware, the backup processor would never get the hazelcast instance injected and the process method could fail with NPE. The fix checks if the entry processor implements HazelcastInstanceAware and supplies a different backup processor in that case.

Fixes : hazelcast#10083
mmedenjak added a commit to mmedenjak/hazelcast that referenced this issue Mar 16, 2017
If the supplied entry procesor extended AbstractEntryProcessor and implemented HazelcastInstanceAware, the backup processor would never get the hazelcast instance injected and the process method could fail with NPE. The fix checks if the entry processor implements HazelcastInstanceAware and supplies a different backup processor in that case.

Fixes : hazelcast#10083
mmedenjak added a commit to mmedenjak/hazelcast that referenced this issue Mar 16, 2017
If the supplied entry procesor extended AbstractEntryProcessor and implemented HazelcastInstanceAware, the backup processor would never get the hazelcast instance injected and the process method could fail with NPE. The fix checks if the entry processor implements HazelcastInstanceAware and supplies a different backup processor in that case.

Fixes : hazelcast#10083

(cherry picked from commit d222005)
@mmedenjak mmedenjak closed this Mar 20, 2017
mmedenjak added a commit to mmedenjak/hazelcast that referenced this issue Apr 11, 2017
If the supplied entry procesor extended AbstractEntryProcessor and
implemented HazelcastInstanceAware, the backup processor would never
get the hazelcast instance injected and the process method could fail
with NPE.

The EntryBackupProcessorImpl now implements HazelcastInstanceAware
which checks if the outer object implements it as well and calls
the method to set the instance.

This changes the serialVersionUID of the EntryBackupProcessorImpl
which would cause it to fail deserialization when sent from a member
containing the fix to a member which doesn't contain the fix. This is
why we set the serialVersionUID to the value calculated for the
EntryBackupProcessorImpl without the fix.

Fixes : hazelcast#10083
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant
You can’t perform that action at this time.