use of io.pravega.shared.controller.event.ControllerEventSerializer in project pravega by pravega.
the class RequestSweeperTest method testRequestSweeperLimits.
@Test(timeout = 30000L)
public void testRequestSweeperLimits() {
doAnswer(x -> CompletableFuture.completedFuture(null)).when(requestEventWriter).writeEvent(any(), any());
List<List<String>> processed = new LinkedList<>();
Consumer<List<String>> consumer = processed::add;
TestRequestSweeper requestSweeper = new TestRequestSweeper(streamStore, executor, streamMetadataTasks, consumer);
ControllerEventSerializer serializer = new ControllerEventSerializer();
HostIndex hostIndex = getHostIndex();
ControllerEvent event1 = new SealStreamEvent("scope", "stream1", 0L);
ControllerEvent event2 = new SealStreamEvent("scope", "stream2", 0L);
ControllerEvent event3 = new SealStreamEvent("scope", "stream3", 0L);
hostIndex.addEntity(HOSTNAME, "entity1", serializer.toByteBuffer(event1).array()).join();
hostIndex.addEntity(HOSTNAME, "entity2", serializer.toByteBuffer(event2).array()).join();
hostIndex.addEntity(HOSTNAME, "entity3", serializer.toByteBuffer(event3).array()).join();
List<String> entities = hostIndex.getEntities(HOSTNAME).join();
assertEquals(entities.size(), 3);
Set<String> hosts = hostIndex.getHosts().join();
assertEquals(hosts.size(), 1);
requestSweeper.handleFailedProcess(HOSTNAME).join();
// after failover all entities and host must have been removed
entities = hostIndex.getEntities(HOSTNAME).join();
assertTrue(entities.isEmpty());
hosts = hostIndex.getHosts().join();
assertTrue(hosts.isEmpty());
// the processing loop should have been called four times.
// first three times, it should get one entity.
// in the exit condition it should get empty list and exit.
assertEquals(processed.size(), 4);
assertEquals(processed.get(0).size(), 1);
assertEquals(processed.get(1).size(), 1);
assertEquals(processed.get(2).size(), 1);
assertEquals(processed.get(3).size(), 0);
}
use of io.pravega.shared.controller.event.ControllerEventSerializer in project pravega by pravega.
the class RequestSweeperTest method testRequestSweeper.
@Test(timeout = 30000)
public void testRequestSweeper() throws ExecutionException, InterruptedException {
AbstractMap.SimpleEntry<Double, Double> segment1 = new AbstractMap.SimpleEntry<>(0.5, 0.75);
AbstractMap.SimpleEntry<Double, Double> segment2 = new AbstractMap.SimpleEntry<>(0.75, 1.0);
List<Long> sealedSegments = Collections.singletonList(1L);
CompletableFuture<Void> wait1 = new CompletableFuture<>();
CompletableFuture<Void> wait2 = new CompletableFuture<>();
LinkedBlockingQueue<CompletableFuture<Void>> waitQueue = new LinkedBlockingQueue<>();
waitQueue.put(wait1);
waitQueue.put(wait2);
CompletableFuture<Void> signal1 = new CompletableFuture<>();
CompletableFuture<Void> signal2 = new CompletableFuture<>();
LinkedBlockingQueue<CompletableFuture<Void>> signalQueue = new LinkedBlockingQueue<>();
signalQueue.put(signal1);
signalQueue.put(signal2);
doAnswer(x -> {
signalQueue.take().complete(null);
return waitQueue.take();
}).when(requestEventWriter).writeEvent(any(), any());
streamMetadataTasks.manualScale(SCOPE, stream1, sealedSegments, Arrays.asList(segment1, segment2), System.currentTimeMillis(), 0L);
signal1.join();
// since we dont complete writeEventFuture, manual scale will not complete and index is not removed
// verify that index has the entry.
HostIndex hostIndex = getHostIndex();
List<String> entities = hostIndex.getEntities(HOSTNAME).join();
assertEquals(1, entities.size());
byte[] data = hostIndex.getEntityData(HOSTNAME, entities.get(0)).join();
ControllerEventSerializer serializer = new ControllerEventSerializer();
ControllerEvent event = serializer.fromByteBuffer(ByteBuffer.wrap(data));
assertTrue(event instanceof ScaleOpEvent);
RequestSweeper requestSweeper = new RequestSweeper(streamStore, executor, streamMetadataTasks);
CompletableFuture<Void> failoverFuture = requestSweeper.handleFailedProcess(HOSTNAME);
// verify that the event is posted.. signal 2 future should be completed.
signal2.join();
// let wait2 be complete as well.
wait2.complete(null);
// wait for failover to complete
failoverFuture.join();
// verify that entity is removed.
entities = hostIndex.getEntities(HOSTNAME).join();
assertTrue(entities.isEmpty());
// verify that the host is removed.
Set<String> hosts = hostIndex.getHosts().join();
assertTrue(hosts.isEmpty());
}
Aggregations