forked from apache/seatunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Improve][Test] Add test for ResourceManager to keep task will be dep…
…loyed in different node (apache#5518) * [Improve][Test] Add test for ResourceManager to keep task will be deployed in different node
- Loading branch information
Showing
5 changed files
with
155 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...src/test/java/org/apache/seatunnel/engine/server/resourcemanager/FakeResourceManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.engine.server.resourcemanager; | ||
|
||
import org.apache.seatunnel.engine.server.resourcemanager.opeartion.RequestSlotOperation; | ||
import org.apache.seatunnel.engine.server.resourcemanager.resource.ResourceProfile; | ||
import org.apache.seatunnel.engine.server.resourcemanager.resource.SlotProfile; | ||
import org.apache.seatunnel.engine.server.resourcemanager.worker.WorkerProfile; | ||
import org.apache.seatunnel.engine.server.service.slot.SlotAndWorkerProfile; | ||
|
||
import com.hazelcast.cluster.Address; | ||
import com.hazelcast.spi.impl.NodeEngine; | ||
import com.hazelcast.spi.impl.operationservice.Operation; | ||
|
||
import java.net.UnknownHostException; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** Used to test ResourceManager, override init method to register more workers. */ | ||
public class FakeResourceManager extends AbstractResourceManager { | ||
public FakeResourceManager(NodeEngine nodeEngine) { | ||
super(nodeEngine); | ||
init(); | ||
} | ||
|
||
@Override | ||
public void init() { | ||
try { | ||
Address address1 = new Address("localhost", 5801); | ||
WorkerProfile workerProfile1 = | ||
new WorkerProfile( | ||
address1, | ||
new ResourceProfile(), | ||
new ResourceProfile(), | ||
new SlotProfile[] {}, | ||
new SlotProfile[] {}); | ||
this.registerWorker.put(address1, workerProfile1); | ||
|
||
Address address2 = new Address("localhost", 5802); | ||
WorkerProfile workerProfile2 = | ||
new WorkerProfile( | ||
address2, | ||
new ResourceProfile(), | ||
new ResourceProfile(), | ||
new SlotProfile[] {}, | ||
new SlotProfile[] {}); | ||
this.registerWorker.put(address2, workerProfile2); | ||
Address address3 = new Address("localhost", 5803); | ||
WorkerProfile workerProfile3 = | ||
new WorkerProfile( | ||
address3, | ||
new ResourceProfile(), | ||
new ResourceProfile(), | ||
new SlotProfile[] {}, | ||
new SlotProfile[] {}); | ||
this.registerWorker.put(address3, workerProfile3); | ||
} catch (UnknownHostException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
protected <E> CompletableFuture<E> sendToMember(Operation operation, Address address) { | ||
if (operation instanceof RequestSlotOperation) { | ||
return (CompletableFuture<E>) | ||
CompletableFuture.completedFuture( | ||
new SlotAndWorkerProfile( | ||
new WorkerProfile( | ||
address, | ||
new ResourceProfile(), | ||
new ResourceProfile(), | ||
new SlotProfile[] {}, | ||
new SlotProfile[] {}), | ||
new SlotProfile(address, 1, new ResourceProfile(), ""))); | ||
} else { | ||
return super.sendToMember(operation, address); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
.../java/org/apache/seatunnel/engine/server/resourcemanager/ResourceManagerFunctionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.engine.server.resourcemanager; | ||
|
||
import org.apache.seatunnel.engine.server.AbstractSeaTunnelServerTest; | ||
import org.apache.seatunnel.engine.server.resourcemanager.resource.ResourceProfile; | ||
import org.apache.seatunnel.engine.server.resourcemanager.resource.SlotProfile; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.hazelcast.cluster.Address; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.stream.Collectors; | ||
|
||
public class ResourceManagerFunctionTest | ||
extends AbstractSeaTunnelServerTest<ResourceManagerFunctionTest> { | ||
|
||
@Test | ||
public void testApplyResourceWithRandomResult() | ||
throws ExecutionException, InterruptedException { | ||
FakeResourceManager resourceManager = new FakeResourceManager(nodeEngine); | ||
|
||
List<ResourceProfile> resourceProfiles = new ArrayList<>(); | ||
resourceProfiles.add(new ResourceProfile()); | ||
resourceProfiles.add(new ResourceProfile()); | ||
resourceProfiles.add(new ResourceProfile()); | ||
resourceProfiles.add(new ResourceProfile()); | ||
resourceProfiles.add(new ResourceProfile()); | ||
List<SlotProfile> slotProfiles = resourceManager.applyResources(1L, resourceProfiles).get(); | ||
Assertions.assertEquals(slotProfiles.size(), 5); | ||
|
||
Set<Address> addresses = | ||
slotProfiles.stream().map(SlotProfile::getWorker).collect(Collectors.toSet()); | ||
Assertions.assertTrue(addresses.size() > 1); | ||
} | ||
} |