Skip to content

Instantly share code, notes, and snippets.

@gurbuzali
Created August 27, 2018 08:13
Show Gist options
  • Save gurbuzali/e33a2eccab91c1f79d95f1054460e98d to your computer and use it in GitHub Desktop.
Save gurbuzali/e33a2eccab91c1f79d95f1054460e98d to your computer and use it in GitHub Desktop.
import com.hazelcast.config.Config;
import com.hazelcast.config.EventJournalConfig;
import com.hazelcast.jet.config.JetConfig;
import com.hazelcast.jet.pipeline.JournalInitialPosition;
import com.hazelcast.jet.pipeline.Pipeline;
import com.hazelcast.jet.pipeline.Sinks;
import com.hazelcast.jet.pipeline.Sources;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.Map;
public class MapDestroyTest {
private JetInstance jet;
@Before
public void setup() {
JetConfig jetConfig = new JetConfig();
Config hazelcastConfig = jetConfig.getHazelcastConfig();
EventJournalConfig eventJournalConfig = new EventJournalConfig();
eventJournalConfig.setMapName("*");
hazelcastConfig.addEventJournalConfig(eventJournalConfig);
jet = Jet.newJetInstance(jetConfig);
}
@After
public void cleanup() {
jet.shutdown();
}
@Test
public void test() throws InterruptedException {
testInternal("map", "list1", "foo1");
Assert.assertEquals("foo1", jet.getList("list1").get(0));
jet.getMap("map").destroy();
testInternal("map", "list2", "foo2");
Assert.assertEquals("foo2", jet.getList("list2").get(0));
}
private void testInternal(String mapName, String listName, String text) throws InterruptedException {
IMapJet<Object, Object> map = jet.getMap(mapName);
Pipeline p = Pipeline.create();
p.drawFrom(Sources.mapJournal(mapName, JournalInitialPosition.START_FROM_OLDEST))
.map(Map.Entry::getValue)
.drainTo(Sinks.list(listName));
Job job = jet.newJob(p);
map.put(text, text);
Thread.sleep(2000);
job.cancel();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment