This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3756 from saksham2105/http-task-stuck-fix
issue-3719: Fix for http task stuck due to NPE
- Loading branch information
Showing
2 changed files
with
157 additions
and
3 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
92 changes: 92 additions & 0 deletions
92
core/src/test/java/com/netflix/conductor/core/storage/DummyPayloadStorageTest.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,92 @@ | ||
/* | ||
* Copyright 2023 Netflix, Inc. | ||
* <p> | ||
* Licensed 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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 com.netflix.conductor.core.storage; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.UnsupportedEncodingException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.netflix.conductor.common.run.ExternalStorageLocation; | ||
import com.netflix.conductor.common.utils.ExternalPayloadStorage; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import static com.netflix.conductor.common.utils.ExternalPayloadStorage.PayloadType; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class DummyPayloadStorageTest { | ||
|
||
private DummyPayloadStorage dummyPayloadStorage; | ||
|
||
private static final String TEST_STORAGE_PATH = "test-storage"; | ||
|
||
private ExternalStorageLocation location; | ||
|
||
private ObjectMapper objectMapper; | ||
|
||
public static final String MOCK_PAYLOAD = "{\n" + "\"output\": \"TEST_OUTPUT\",\n" + "}\n"; | ||
|
||
@Before | ||
public void setup() { | ||
dummyPayloadStorage = new DummyPayloadStorage(); | ||
objectMapper = new ObjectMapper(); | ||
location = | ||
dummyPayloadStorage.getLocation( | ||
ExternalPayloadStorage.Operation.WRITE, | ||
PayloadType.TASK_OUTPUT, | ||
TEST_STORAGE_PATH); | ||
try { | ||
byte[] payloadBytes = MOCK_PAYLOAD.getBytes("UTF-8"); | ||
dummyPayloadStorage.upload( | ||
location.getPath(), | ||
new ByteArrayInputStream(payloadBytes), | ||
payloadBytes.length); | ||
} catch (UnsupportedEncodingException unsupportedEncodingException) { | ||
} | ||
} | ||
|
||
@Test | ||
public void testGetLocationNotNull() { | ||
assertNotNull(location); | ||
} | ||
|
||
@Test | ||
public void testDownloadForValidPath() { | ||
try (InputStream inputStream = dummyPayloadStorage.download(location.getPath())) { | ||
Map<String, Object> payload = | ||
objectMapper.readValue( | ||
IOUtils.toString(inputStream, StandardCharsets.UTF_8), Map.class); | ||
assertTrue(payload.containsKey("output")); | ||
assertEquals(payload.get("output"), "TEST_OUTPUT"); | ||
} catch (Exception e) { | ||
assertTrue(e instanceof IOException); | ||
} | ||
} | ||
|
||
@Test | ||
public void testDownloadForInvalidPath() { | ||
InputStream inputStream = dummyPayloadStorage.download("testPath"); | ||
assertNull(inputStream); | ||
} | ||
} |