-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling throwable during Helix message processing #2696
Closed
csudharsanan
wants to merge
1
commit into
apache:master
from
csudharsanan:csudhars/error-handling-message-processing
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
96 changes: 0 additions & 96 deletions
96
helix-core/src/test/java/org/apache/helix/TestHelixTaskExecutor.java
This file was deleted.
Oops, something went wrong.
132 changes: 132 additions & 0 deletions
132
helix-core/src/test/java/org/apache/helix/messaging/handling/TestCMTaskExecutor.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,132 @@ | ||
package org.apache.helix.messaging.handling; | ||
|
||
/* | ||
* 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. | ||
*/ | ||
|
||
import org.apache.helix.HelixDataAccessor; | ||
import org.apache.helix.NotificationContext; | ||
import org.apache.helix.PropertyKey.Builder; | ||
import org.apache.helix.mock.MockManager; | ||
import org.apache.helix.mock.participant.MockHelixTaskExecutor; | ||
import org.apache.helix.mock.statemodel.MockMasterSlaveStateModel; | ||
import org.apache.helix.model.CurrentState; | ||
import org.apache.helix.model.Message; | ||
import org.apache.helix.model.Message.MessageType; | ||
import org.apache.helix.model.StateModelDefinition; | ||
import org.apache.helix.participant.statemachine.StateModelFactory; | ||
import org.apache.helix.tools.StateModelConfigGenerator; | ||
import org.mockito.MockitoAnnotations; | ||
import org.mockito.Spy; | ||
import org.testng.AssertJUnit; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.doThrow; | ||
|
||
public class TestCMTaskExecutor { | ||
|
||
@Spy | ||
private HelixTaskExecutor _helixTaskExecutor; | ||
private MockHelixTaskExecutor executor; | ||
private MockMasterSlaveStateModel stateModel; | ||
private HelixTask task; | ||
|
||
@BeforeMethod | ||
public void beforeMethod() { | ||
MockitoAnnotations.initMocks(this); | ||
task = getHelixTask(); | ||
} | ||
|
||
public HelixTask getHelixTask() { | ||
String msgId = "TestMessageId"; | ||
Message message = new Message(MessageType.TASK_REPLY, msgId); | ||
|
||
message.setMsgId(msgId); | ||
message.setSrcName("cm-instance-0"); | ||
message.setTgtName("cm-instance-1"); | ||
message.setTgtSessionId("1234"); | ||
message.setFromState("Offline"); | ||
message.setToState("Slave"); | ||
message.setPartitionName("TestDB_0"); | ||
message.setResourceName("TestDB"); | ||
message.setStateModelDef("MasterSlave"); | ||
|
||
MockManager manager = new MockManager("clusterName"); | ||
HelixDataAccessor accessor = manager.getHelixDataAccessor(); | ||
StateModelDefinition stateModelDef = | ||
new StateModelDefinition(StateModelConfigGenerator.generateConfigForMasterSlave()); | ||
Builder keyBuilder = accessor.keyBuilder(); | ||
accessor.setProperty(keyBuilder.stateModelDef("MasterSlave"), stateModelDef); | ||
|
||
executor = new MockHelixTaskExecutor(); | ||
stateModel = new MockMasterSlaveStateModel(); | ||
executor.registerMessageHandlerFactory(MessageType.TASK_REPLY.name(), | ||
new AsyncCallbackService()); | ||
|
||
NotificationContext context = new NotificationContext(manager); | ||
CurrentState currentStateDelta = new CurrentState("TestDB"); | ||
currentStateDelta.setState("TestDB_0", "OFFLINE"); | ||
|
||
StateModelFactory<MockMasterSlaveStateModel> stateModelFactory = new StateModelFactory<MockMasterSlaveStateModel>() { | ||
|
||
@Override | ||
public MockMasterSlaveStateModel createNewStateModel(String resource, String partitionName) { | ||
// TODO Auto-generated method stub | ||
return new MockMasterSlaveStateModel(); | ||
} | ||
|
||
}; | ||
HelixStateTransitionHandler handler = | ||
new HelixStateTransitionHandler(stateModelFactory, stateModel, message, context, | ||
currentStateDelta); | ||
|
||
return new HelixTask(message, context, handler, executor); | ||
} | ||
|
||
@DataProvider(name = "throwableClass") | ||
public static Object[][] throwableClass() { | ||
return new Object[][]{ | ||
{OutOfMemoryError.class}, | ||
{IllegalStateException.class} | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "throwableClass") | ||
public void testThrowableHandlingOnMessageProcess(Class throwable) { | ||
doThrow(throwable).when(_helixTaskExecutor).updateStateTransitionMessageThreadPool(any(), any()); | ||
boolean isScheduled = _helixTaskExecutor.scheduleTask(task); | ||
AssertJUnit.assertFalse(isScheduled); | ||
} | ||
|
||
@Test() | ||
public void testCMTaskExecutor() throws Exception { | ||
System.out.println("START TestCMTaskExecutor"); | ||
executor.scheduleTask(task); | ||
for (int i = 0; i < 10; i++) { | ||
if (!executor.isDone(task.getTaskId())) { | ||
Thread.sleep(500); | ||
} | ||
} | ||
AssertJUnit.assertTrue(stateModel.stateModelInvoked); | ||
System.out.println("END TestCMTaskExecutor"); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider not integrate the Throwable in message. If we do it this way, it only print out a short description of this throwable.
We may want to print the stack trace and other information. Please consider something like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can close this one, as created #2730 for addressing the comments