Wenjun Ruan
1 month ago
committed by
GitHub
40 changed files with 304 additions and 775 deletions
@ -1,58 +0,0 @@
|
||||
/* |
||||
* 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.dolphinscheduler.server.master.registry; |
||||
|
||||
import org.apache.dolphinscheduler.registry.api.RegistryClient; |
||||
import org.apache.dolphinscheduler.registry.api.StrategyType; |
||||
import org.apache.dolphinscheduler.server.master.config.MasterConfig; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* This strategy will stop the master server, when disconnected from {@link org.apache.dolphinscheduler.registry.api.Registry}. |
||||
*/ |
||||
@Service |
||||
@ConditionalOnProperty(prefix = "master.registry-disconnect-strategy", name = "strategy", havingValue = "stop", matchIfMissing = true) |
||||
@Slf4j |
||||
public class MasterStopStrategy implements MasterConnectStrategy { |
||||
|
||||
@Autowired |
||||
private RegistryClient registryClient; |
||||
@Autowired |
||||
private MasterConfig masterConfig; |
||||
|
||||
@Override |
||||
public void disconnect() { |
||||
registryClient.getStoppable() |
||||
.stop("Master disconnected from registry, will stop myself due to the stop strategy"); |
||||
} |
||||
|
||||
@Override |
||||
public void reconnect() { |
||||
log.warn("The current connect strategy is stop, so the master will not reconnect to registry"); |
||||
} |
||||
|
||||
@Override |
||||
public StrategyType getStrategyType() { |
||||
return StrategyType.STOP; |
||||
} |
||||
} |
@ -1,116 +0,0 @@
|
||||
/* |
||||
* 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.dolphinscheduler.server.master.registry; |
||||
|
||||
import org.apache.dolphinscheduler.common.lifecycle.ServerLifeCycleException; |
||||
import org.apache.dolphinscheduler.common.lifecycle.ServerLifeCycleManager; |
||||
import org.apache.dolphinscheduler.common.lifecycle.ServerStatus; |
||||
import org.apache.dolphinscheduler.registry.api.Registry; |
||||
import org.apache.dolphinscheduler.registry.api.RegistryClient; |
||||
import org.apache.dolphinscheduler.registry.api.RegistryException; |
||||
import org.apache.dolphinscheduler.registry.api.StrategyType; |
||||
import org.apache.dolphinscheduler.server.master.config.MasterConfig; |
||||
import org.apache.dolphinscheduler.server.master.engine.IWorkflowRepository; |
||||
|
||||
import java.time.Duration; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* This strategy will change the server status to {@link ServerStatus#WAITING} when disconnect from {@link Registry}. |
||||
*/ |
||||
@Service |
||||
@ConditionalOnProperty(prefix = "master.registry-disconnect-strategy", name = "strategy", havingValue = "waiting") |
||||
@Slf4j |
||||
public class MasterWaitingStrategy implements MasterConnectStrategy { |
||||
|
||||
@Autowired |
||||
private MasterConfig masterConfig; |
||||
@Autowired |
||||
private RegistryClient registryClient; |
||||
@Autowired |
||||
private IWorkflowRepository IWorkflowRepository; |
||||
|
||||
@Override |
||||
public void disconnect() { |
||||
try { |
||||
ServerLifeCycleManager.toWaiting(); |
||||
clearMasterResource(); |
||||
Duration maxWaitingTime = masterConfig.getRegistryDisconnectStrategy().getMaxWaitingTime(); |
||||
try { |
||||
log.info("Master disconnect from registry will try to reconnect in {} s", |
||||
maxWaitingTime.getSeconds()); |
||||
registryClient.connectUntilTimeout(maxWaitingTime); |
||||
} catch (RegistryException ex) { |
||||
throw new ServerLifeCycleException( |
||||
String.format("Waiting to reconnect to registry in %s failed", maxWaitingTime), ex); |
||||
} |
||||
} catch (ServerLifeCycleException e) { |
||||
String errorMessage = String.format( |
||||
"Disconnect from registry and change the current status to waiting error, the current server state is %s, will stop the current server", |
||||
ServerLifeCycleManager.getServerStatus()); |
||||
log.error(errorMessage, e); |
||||
registryClient.getStoppable().stop(errorMessage); |
||||
} catch (RegistryException ex) { |
||||
String errorMessage = "Disconnect from registry and waiting to reconnect failed, will stop the server"; |
||||
log.error(errorMessage, ex); |
||||
registryClient.getStoppable().stop(errorMessage); |
||||
} catch (Exception ex) { |
||||
String errorMessage = "Disconnect from registry and get an unknown exception, will stop the server"; |
||||
log.error(errorMessage, ex); |
||||
registryClient.getStoppable().stop(errorMessage); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void reconnect() { |
||||
if (ServerLifeCycleManager.isRunning()) { |
||||
log.info("no need to reconnect, as the current server status is running"); |
||||
} else { |
||||
try { |
||||
ServerLifeCycleManager.recoverFromWaiting(); |
||||
log.info("Recover from waiting success, the current server status is {}", |
||||
ServerLifeCycleManager.getServerStatus()); |
||||
} catch (Exception e) { |
||||
String errorMessage = |
||||
String.format( |
||||
"Recover from waiting failed, the current server status is %s, will stop the server", |
||||
ServerLifeCycleManager.getServerStatus()); |
||||
log.error(errorMessage, e); |
||||
registryClient.getStoppable().stop(errorMessage); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public StrategyType getStrategyType() { |
||||
return StrategyType.WAITING; |
||||
} |
||||
|
||||
private void clearMasterResource() { |
||||
log.warn("Master clear workflow event queue due to lost registry connection"); |
||||
IWorkflowRepository.clear(); |
||||
log.warn("Master clear workflow instance cache due to lost registry connection"); |
||||
|
||||
} |
||||
|
||||
} |
@ -1,31 +0,0 @@
|
||||
/* |
||||
* 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.dolphinscheduler.registry.api; |
||||
|
||||
import java.time.Duration; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class ConnectStrategyProperties { |
||||
|
||||
private StrategyType strategy = StrategyType.STOP; |
||||
|
||||
private Duration maxWaitingTime = Duration.ofSeconds(0); |
||||
|
||||
} |
@ -1,25 +0,0 @@
|
||||
/* |
||||
* 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.dolphinscheduler.registry.api; |
||||
|
||||
public enum StrategyType { |
||||
|
||||
STOP, |
||||
WAITING, |
||||
; |
||||
} |
@ -1,24 +0,0 @@
|
||||
/* |
||||
* 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.dolphinscheduler.server.worker.registry; |
||||
|
||||
import org.apache.dolphinscheduler.registry.api.ConnectStrategy; |
||||
|
||||
public interface WorkerConnectStrategy extends ConnectStrategy { |
||||
|
||||
} |
@ -1,52 +0,0 @@
|
||||
/* |
||||
* 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.dolphinscheduler.server.worker.registry; |
||||
|
||||
import org.apache.dolphinscheduler.registry.api.RegistryClient; |
||||
import org.apache.dolphinscheduler.registry.api.StrategyType; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
@ConditionalOnProperty(prefix = "worker.registry-disconnect-strategy", name = "strategy", havingValue = "stop", matchIfMissing = true) |
||||
@Slf4j |
||||
public class WorkerStopStrategy implements WorkerConnectStrategy { |
||||
|
||||
@Autowired |
||||
public RegistryClient registryClient; |
||||
|
||||
@Override |
||||
public void disconnect() { |
||||
registryClient.getStoppable() |
||||
.stop("Worker disconnected from registry, will stop myself due to the stop strategy"); |
||||
} |
||||
|
||||
@Override |
||||
public void reconnect() { |
||||
log.warn("The current connect strategy is stop, so the worker will not reconnect to registry"); |
||||
} |
||||
|
||||
@Override |
||||
public StrategyType getStrategyType() { |
||||
return StrategyType.STOP; |
||||
} |
||||
} |
@ -1,131 +0,0 @@
|
||||
/* |
||||
* 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.dolphinscheduler.server.worker.registry; |
||||
|
||||
import org.apache.dolphinscheduler.common.lifecycle.ServerLifeCycleException; |
||||
import org.apache.dolphinscheduler.common.lifecycle.ServerLifeCycleManager; |
||||
import org.apache.dolphinscheduler.registry.api.RegistryClient; |
||||
import org.apache.dolphinscheduler.registry.api.RegistryException; |
||||
import org.apache.dolphinscheduler.registry.api.StrategyType; |
||||
import org.apache.dolphinscheduler.server.worker.config.WorkerConfig; |
||||
import org.apache.dolphinscheduler.server.worker.message.MessageRetryRunner; |
||||
import org.apache.dolphinscheduler.server.worker.runner.WorkerTaskExecutorHolder; |
||||
import org.apache.dolphinscheduler.server.worker.runner.WorkerTaskExecutorThreadPool; |
||||
|
||||
import java.time.Duration; |
||||
|
||||
import lombok.NonNull; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
@ConditionalOnProperty(prefix = "worker.registry-disconnect-strategy", name = "strategy", havingValue = "waiting") |
||||
@Slf4j |
||||
public class WorkerWaitingStrategy implements WorkerConnectStrategy { |
||||
|
||||
@Autowired |
||||
private WorkerConfig workerConfig; |
||||
|
||||
@Autowired |
||||
private RegistryClient registryClient; |
||||
|
||||
@Autowired |
||||
private MessageRetryRunner messageRetryRunner; |
||||
|
||||
@Autowired |
||||
private WorkerTaskExecutorThreadPool workerManagerThread; |
||||
|
||||
public WorkerWaitingStrategy(@NonNull WorkerConfig workerConfig, |
||||
@NonNull RegistryClient registryClient, |
||||
@NonNull MessageRetryRunner messageRetryRunner, |
||||
@NonNull WorkerTaskExecutorThreadPool workerManagerThread) { |
||||
this.workerConfig = workerConfig; |
||||
this.registryClient = registryClient; |
||||
this.messageRetryRunner = messageRetryRunner; |
||||
this.workerManagerThread = workerManagerThread; |
||||
} |
||||
|
||||
@Override |
||||
public void disconnect() { |
||||
try { |
||||
ServerLifeCycleManager.toWaiting(); |
||||
clearWorkerResource(); |
||||
Duration maxWaitingTime = workerConfig.getRegistryDisconnectStrategy().getMaxWaitingTime(); |
||||
try { |
||||
log.info("Worker disconnect from registry will try to reconnect in {} s", |
||||
maxWaitingTime.getSeconds()); |
||||
registryClient.connectUntilTimeout(maxWaitingTime); |
||||
} catch (RegistryException ex) { |
||||
throw new ServerLifeCycleException( |
||||
String.format("Waiting to reconnect to registry in %s failed", maxWaitingTime), ex); |
||||
} |
||||
|
||||
} catch (ServerLifeCycleException e) { |
||||
String errorMessage = String.format( |
||||
"Disconnect from registry and change the current status to waiting error, the current server state is %s, will stop the current server", |
||||
ServerLifeCycleManager.getServerStatus()); |
||||
log.error(errorMessage, e); |
||||
registryClient.getStoppable().stop(errorMessage); |
||||
} catch (RegistryException ex) { |
||||
String errorMessage = "Disconnect from registry and waiting to reconnect failed, will stop the server"; |
||||
log.error(errorMessage, ex); |
||||
registryClient.getStoppable().stop(errorMessage); |
||||
} catch (Exception ex) { |
||||
String errorMessage = "Disconnect from registry and get an unknown exception, will stop the server"; |
||||
log.error(errorMessage, ex); |
||||
registryClient.getStoppable().stop(errorMessage); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void reconnect() { |
||||
if (ServerLifeCycleManager.isRunning()) { |
||||
log.info("no need to reconnect, as the current server status is running"); |
||||
} else { |
||||
try { |
||||
ServerLifeCycleManager.recoverFromWaiting(); |
||||
log.info("Recover from waiting success, the current server status is {}", |
||||
ServerLifeCycleManager.getServerStatus()); |
||||
} catch (Exception e) { |
||||
String errorMessage = |
||||
String.format( |
||||
"Recover from waiting failed, the current server status is %s, will stop the server", |
||||
ServerLifeCycleManager.getServerStatus()); |
||||
log.error(errorMessage, e); |
||||
registryClient.getStoppable().stop(errorMessage); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public StrategyType getStrategyType() { |
||||
return StrategyType.WAITING; |
||||
} |
||||
|
||||
private void clearWorkerResource() { |
||||
workerManagerThread.clearTask(); |
||||
WorkerTaskExecutorHolder.clear(); |
||||
log.warn("Worker server clear the tasks due to lost connection from registry"); |
||||
messageRetryRunner.clearMessage(); |
||||
log.warn("Worker server clear the retry message due to lost connection from registry"); |
||||
} |
||||
|
||||
} |
@ -1,187 +0,0 @@
|
||||
/* |
||||
* 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.dolphinscheduler.server.worker.registry; |
||||
|
||||
import static org.mockito.ArgumentMatchers.any; |
||||
import static org.mockito.ArgumentMatchers.anyString; |
||||
import static org.mockito.BDDMockito.given; |
||||
import static org.mockito.Mockito.doNothing; |
||||
|
||||
import org.apache.dolphinscheduler.common.IStoppable; |
||||
import org.apache.dolphinscheduler.common.lifecycle.ServerLifeCycleException; |
||||
import org.apache.dolphinscheduler.common.lifecycle.ServerLifeCycleManager; |
||||
import org.apache.dolphinscheduler.registry.api.ConnectStrategyProperties; |
||||
import org.apache.dolphinscheduler.registry.api.RegistryClient; |
||||
import org.apache.dolphinscheduler.registry.api.RegistryException; |
||||
import org.apache.dolphinscheduler.registry.api.StrategyType; |
||||
import org.apache.dolphinscheduler.server.worker.config.WorkerConfig; |
||||
import org.apache.dolphinscheduler.server.worker.message.MessageRetryRunner; |
||||
import org.apache.dolphinscheduler.server.worker.rpc.WorkerRpcServer; |
||||
import org.apache.dolphinscheduler.server.worker.runner.WorkerTaskExecutorThreadPool; |
||||
|
||||
import java.time.Duration; |
||||
|
||||
import org.junit.jupiter.api.Assertions; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.mockito.Mock; |
||||
import org.mockito.MockedStatic; |
||||
import org.mockito.Mockito; |
||||
import org.mockito.junit.jupiter.MockitoExtension; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
/** |
||||
* worker registry test |
||||
*/ |
||||
@ExtendWith(MockitoExtension.class) |
||||
public class WorkerStrategyTest { |
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(WorkerStrategyTest.class); |
||||
@Mock |
||||
private RegistryClient registryClient; |
||||
@Mock |
||||
private IStoppable stoppable; |
||||
@Mock |
||||
private WorkerConfig workerConfig; |
||||
@Mock |
||||
private WorkerRpcServer workerRpcServer; |
||||
@Mock |
||||
private MessageRetryRunner messageRetryRunner; |
||||
@Mock |
||||
private WorkerTaskExecutorThreadPool workerManagerThread; |
||||
@Mock |
||||
private ConnectStrategyProperties connectStrategyProperties; |
||||
|
||||
@Test |
||||
public void testWorkerStopStrategy() { |
||||
given(registryClient.getStoppable()) |
||||
.willReturn(stoppable); |
||||
WorkerStopStrategy workerStopStrategy = new WorkerStopStrategy(); |
||||
workerStopStrategy.registryClient = registryClient; |
||||
workerStopStrategy.reconnect(); |
||||
workerStopStrategy.disconnect(); |
||||
Assertions.assertEquals(workerStopStrategy.getStrategyType(), StrategyType.STOP); |
||||
} |
||||
|
||||
@Test |
||||
public void testWorkerWaitingStrategyreconnect() { |
||||
WorkerWaitingStrategy workerWaitingStrategy = new WorkerWaitingStrategy( |
||||
workerConfig, |
||||
registryClient, |
||||
messageRetryRunner, |
||||
workerManagerThread); |
||||
Assertions.assertEquals(workerWaitingStrategy.getStrategyType(), StrategyType.WAITING); |
||||
|
||||
try ( |
||||
MockedStatic<ServerLifeCycleManager> serverLifeCycleManagerMockedStatic = |
||||
Mockito.mockStatic(ServerLifeCycleManager.class)) { |
||||
serverLifeCycleManagerMockedStatic |
||||
.when(() -> ServerLifeCycleManager.isRunning()) |
||||
.thenReturn(true); |
||||
workerWaitingStrategy.reconnect(); |
||||
|
||||
} |
||||
|
||||
try ( |
||||
MockedStatic<ServerLifeCycleManager> serverLifeCycleManagerMockedStatic = |
||||
Mockito.mockStatic(ServerLifeCycleManager.class)) { |
||||
doNothing().when(stoppable).stop(anyString()); |
||||
given(registryClient.getStoppable()) |
||||
.willReturn(stoppable); |
||||
serverLifeCycleManagerMockedStatic |
||||
.when(() -> ServerLifeCycleManager.recoverFromWaiting()) |
||||
.thenThrow(new ServerLifeCycleException("")); |
||||
workerWaitingStrategy.reconnect(); |
||||
} |
||||
|
||||
try ( |
||||
MockedStatic<ServerLifeCycleManager> serverLifeCycleManagerMockedStatic = |
||||
Mockito.mockStatic(ServerLifeCycleManager.class)) { |
||||
serverLifeCycleManagerMockedStatic |
||||
.when(() -> ServerLifeCycleManager.recoverFromWaiting()) |
||||
.thenAnswer(invocation -> null); |
||||
workerWaitingStrategy.reconnect(); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void testWorkerWaitingStrategydisconnect() { |
||||
WorkerWaitingStrategy workerWaitingStrategy = new WorkerWaitingStrategy( |
||||
workerConfig, |
||||
registryClient, |
||||
messageRetryRunner, |
||||
workerManagerThread); |
||||
Assertions.assertEquals(workerWaitingStrategy.getStrategyType(), StrategyType.WAITING); |
||||
|
||||
try ( |
||||
MockedStatic<ServerLifeCycleManager> serverLifeCycleManagerMockedStatic = |
||||
Mockito.mockStatic(ServerLifeCycleManager.class)) { |
||||
doNothing().when(stoppable).stop(anyString()); |
||||
given(registryClient.getStoppable()) |
||||
.willReturn(stoppable); |
||||
serverLifeCycleManagerMockedStatic |
||||
.when(() -> ServerLifeCycleManager.toWaiting()) |
||||
.thenThrow(new ServerLifeCycleException("")); |
||||
workerWaitingStrategy.disconnect(); |
||||
} |
||||
|
||||
try ( |
||||
MockedStatic<ServerLifeCycleManager> serverLifeCycleManagerMockedStatic = |
||||
Mockito.mockStatic(ServerLifeCycleManager.class)) { |
||||
given(connectStrategyProperties.getMaxWaitingTime()).willReturn(Duration.ofSeconds(1)); |
||||
given(workerConfig.getRegistryDisconnectStrategy()).willReturn(connectStrategyProperties); |
||||
Mockito.reset(registryClient); |
||||
doNothing().when(registryClient).connectUntilTimeout(any()); |
||||
serverLifeCycleManagerMockedStatic |
||||
.when(() -> ServerLifeCycleManager.toWaiting()) |
||||
.thenAnswer(invocation -> null); |
||||
workerWaitingStrategy.disconnect(); |
||||
} |
||||
|
||||
try ( |
||||
MockedStatic<ServerLifeCycleManager> serverLifeCycleManagerMockedStatic = |
||||
Mockito.mockStatic(ServerLifeCycleManager.class)) { |
||||
given(connectStrategyProperties.getMaxWaitingTime()).willReturn(Duration.ofSeconds(1)); |
||||
given(workerConfig.getRegistryDisconnectStrategy()).willReturn(connectStrategyProperties); |
||||
Mockito.reset(registryClient); |
||||
doNothing().when(stoppable).stop(anyString()); |
||||
given(registryClient.getStoppable()) |
||||
.willReturn(stoppable); |
||||
Mockito.doThrow(new RegistryException("TEST")).when(registryClient).connectUntilTimeout(any()); |
||||
serverLifeCycleManagerMockedStatic |
||||
.when(() -> ServerLifeCycleManager.toWaiting()) |
||||
.thenAnswer(invocation -> null); |
||||
workerWaitingStrategy.disconnect(); |
||||
} |
||||
|
||||
try ( |
||||
MockedStatic<ServerLifeCycleManager> serverLifeCycleManagerMockedStatic = |
||||
Mockito.mockStatic(ServerLifeCycleManager.class)) { |
||||
Mockito.reset(workerConfig); |
||||
given(workerConfig.getRegistryDisconnectStrategy()).willThrow(new NullPointerException("")); |
||||
doNothing().when(stoppable).stop(anyString()); |
||||
given(registryClient.getStoppable()) |
||||
.willReturn(stoppable); |
||||
serverLifeCycleManagerMockedStatic |
||||
.when(() -> ServerLifeCycleManager.toWaiting()) |
||||
.thenAnswer(invocation -> null); |
||||
workerWaitingStrategy.disconnect(); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue