Skip to content

Commit

Permalink
Handle status failures for streaming supervisors (#15174)
Browse files Browse the repository at this point in the history
* Cleanup logic

* newline

* remove whitespace

* Fix log message

* Add test class

* PR changes
  • Loading branch information
georgew5656 authored Oct 30, 2023
1 parent a27598a commit 3173093
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.inject.Inject;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.server.initialization.jetty.BadRequestException;
import org.apache.druid.server.initialization.jetty.ServiceUnavailableException;
import org.apache.druid.server.metrics.DataSourceTaskIdHolder;

import javax.ws.rs.Path;
Expand Down Expand Up @@ -73,6 +74,7 @@ public Object doTaskChat(@PathParam("id") String handlerId, @Context HttpHeaders
return handler.get();
}

throw new BadRequestException(StringUtils.format("Can't find chatHandler for handler[%s]", handlerId));
// Return HTTP 503 so SpecificTaskRetryPolicy retries in case the handler is not registered yet or has been registered before shutdown.
throw new ServiceUnavailableException(StringUtils.format("Can't find chatHandler for handler[%s]", handlerId));
}
}
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.druid.segment.realtime.firehose;

import com.google.common.base.Optional;
import org.apache.druid.server.initialization.jetty.ServiceUnavailableException;
import org.apache.druid.server.metrics.DataSourceTaskIdHolder;
import org.easymock.EasyMock;
import org.easymock.EasyMockRunner;
import org.easymock.EasyMockSupport;
import org.easymock.Mock;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(EasyMockRunner.class)
public class ChatHandlerResourceTest extends EasyMockSupport
{

@Mock
ChatHandlerProvider handlers;
@Mock
DataSourceTaskIdHolder dataSourceTaskIdHolder;
ChatHandlerResource chatHandlerResource;

@Test
public void test_noHandlerFound()
{
String handlerId = "handlerId";
EasyMock.expect(dataSourceTaskIdHolder.getTaskId()).andReturn(null);
EasyMock.expect(handlers.get(handlerId)).andReturn(Optional.absent());

replayAll();
chatHandlerResource = new ChatHandlerResource(handlers, dataSourceTaskIdHolder);
Assert.assertThrows(ServiceUnavailableException.class, () -> chatHandlerResource.doTaskChat(handlerId, null));
verifyAll();
}
}

0 comments on commit 3173093

Please sign in to comment.