use of io.prestosql.spi.seedstore.Seed in project hetu-core by openlookeng.
the class TestFileBasedSeedStore method testSeedCreate.
/**
* Test Seed Creation
*/
@Test
public void testSeedCreate() {
Map<String, String> prop = new HashMap<>(0);
String location = "120.0.0.1";
String timestamp = "100";
prop.put(Seed.LOCATION_PROPERTY_NAME, location);
prop.put(Seed.TIMESTAMP_PROPERTY_NAME, timestamp);
Seed seed = seedStore.create(prop);
assertEquals(seed.getLocation(), location);
assertEquals(String.valueOf(seed.getTimestamp()), timestamp);
}
use of io.prestosql.spi.seedstore.Seed in project hetu-core by openlookeng.
the class FileBasedSeedStore method getSeeds.
private Set<Seed> getSeeds() throws IOException {
Set<Seed> outputs = new HashSet<>(0);
StringBuilder content = new StringBuilder(0);
if (fs.exists(seedFilePath)) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(fs.newInputStream(seedFilePath), StandardCharsets.UTF_8))) {
br.lines().forEach(content::append);
}
}
Set<String> seedsStrings = Stream.of(content.toString().split(COMMA)).filter(e -> !e.isEmpty()).collect(Collectors.toSet());
for (String str : seedsStrings) {
try {
outputs.add(FileBasedSeed.deserialize(str));
} catch (ClassNotFoundException e) {
LOG.error("Seed string: %s cannot be deserialized", str);
}
}
return outputs;
}
use of io.prestosql.spi.seedstore.Seed in project hetu-core by openlookeng.
the class TestHetuMetastoreGlobalCache method setUpHazelcast.
@BeforeTest
private void setUpHazelcast() throws IOException {
Set<Seed> seeds = new HashSet<>();
SeedStore mockSeedStore = mock(SeedStore.class);
Seed mockSeed = mock(Seed.class);
seeds.add(mockSeed);
SeedStoreManager mockSeedStoreManager = mock(SeedStoreManager.class);
when(mockSeedStoreManager.getSeedStore(any(SeedStoreSubType.class))).thenReturn(mockSeedStore);
when(mockSeed.getLocation()).thenReturn(LOCALHOST + ":" + PORT3);
when(mockSeedStore.get()).thenReturn(seeds);
factory = new HazelcastStateStoreFactory();
stateStoreProvider = new LocalStateStoreProvider(mockSeedStoreManager);
stateStoreProvider.addStateStoreFactory(factory);
}
use of io.prestosql.spi.seedstore.Seed in project hetu-core by openlookeng.
the class TestSeedStoreManager method testClearExpiredSeed.
@Test
void testClearExpiredSeed() throws Exception {
String location1 = "location1";
String location2 = "location2";
seedStoreManager.loadSeedStore();
seedStoreManager.addSeed(SeedStoreSubType.HAZELCAST, location1, false);
seedStoreManager.addSeed(SeedStoreSubType.HAZELCAST, location2, true);
Assert.assertEquals(seedStoreManager.getAllSeeds(SeedStoreSubType.HAZELCAST).size(), 2);
// wait 5 seconds, location1 expired since refreshable is not enabled
Thread.sleep(5000);
seedStoreManager.clearExpiredSeeds(SeedStoreSubType.HAZELCAST);
Collection<Seed> result = seedStoreManager.getAllSeeds(SeedStoreSubType.HAZELCAST);
Assert.assertEquals(result.size(), 1);
Assert.assertFalse(result.stream().filter(s -> s.getLocation().equals(location1)).findAny().isPresent());
}
use of io.prestosql.spi.seedstore.Seed in project hetu-core by openlookeng.
the class TestSeedStoreManager method testRemoveFromSeedStore.
@Test
void testRemoveFromSeedStore() throws Exception {
String location1 = "location1";
String location2 = "location2";
String location3 = "location3";
seedStoreManager.loadSeedStore();
seedStoreManager.addSeed(SeedStoreSubType.HAZELCAST, location1, false);
seedStoreManager.addSeed(SeedStoreSubType.HAZELCAST, location2, true);
Assert.assertEquals(seedStoreManager.getAllSeeds(SeedStoreSubType.HAZELCAST).size(), 2);
seedStoreManager.removeSeed(SeedStoreSubType.HAZELCAST, location1);
seedStoreManager.removeSeed(SeedStoreSubType.HAZELCAST, location3);
Collection<Seed> result = seedStoreManager.getAllSeeds(SeedStoreSubType.HAZELCAST);
Assert.assertEquals(result.size(), 1);
Assert.assertFalse(result.stream().filter(s -> s.getLocation().equals(location1)).findAny().isPresent());
}
Aggregations