Search in sources :

Example 1 with ArgumentMatchers.anyString

use of org.mockito.ArgumentMatchers.anyString in project ExoPlayer by google.

the class CronetDataSourceTest method requestHeadersSet.

@Test
public void requestHeadersSet() throws HttpDataSourceException {
    Map<String, String> headersSet = new HashMap<>();
    doAnswer((invocation) -> {
        String key = invocation.getArgument(0);
        String value = invocation.getArgument(1);
        headersSet.put(key, value);
        return null;
    }).when(mockUrlRequestBuilder).addHeader(ArgumentMatchers.anyString(), ArgumentMatchers.anyString());
    dataSourceUnderTest.setRequestProperty("defaultHeader2", "dataSourceOverridesDefault");
    dataSourceUnderTest.setRequestProperty("dataSourceHeader1", "dataSourceValue1");
    dataSourceUnderTest.setRequestProperty("dataSourceHeader2", "dataSourceValue2");
    Map<String, String> dataSpecRequestProperties = new HashMap<>();
    dataSpecRequestProperties.put("defaultHeader3", "dataSpecOverridesAll");
    dataSpecRequestProperties.put("dataSourceHeader2", "dataSpecOverridesDataSource");
    dataSpecRequestProperties.put("dataSpecHeader1", "dataSpecValue1");
    testDataSpec = new DataSpec.Builder().setUri(TEST_URL).setHttpRequestHeaders(dataSpecRequestProperties).build();
    mockResponseStartSuccess();
    dataSourceUnderTest.open(testDataSpec);
    assertThat(headersSet.get("defaultHeader1")).isEqualTo("defaultValue1");
    assertThat(headersSet.get("defaultHeader2")).isEqualTo("dataSourceOverridesDefault");
    assertThat(headersSet.get("defaultHeader3")).isEqualTo("dataSpecOverridesAll");
    assertThat(headersSet.get("dataSourceHeader1")).isEqualTo("dataSourceValue1");
    assertThat(headersSet.get("dataSourceHeader2")).isEqualTo("dataSpecOverridesDataSource");
    assertThat(headersSet.get("dataSpecHeader1")).isEqualTo("dataSpecValue1");
    verify(mockUrlRequest).start();
}
Also used : HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with ArgumentMatchers.anyString

use of org.mockito.ArgumentMatchers.anyString in project alluxio by Alluxio.

the class LostStorageIntegrationTest method lostStorageWhenRestart.

@Test
@Ignore
public void lostStorageWhenRestart() throws Exception {
    File ssdDir = Files.createTempDir();
    String ssdPath = ssdDir.getAbsolutePath();
    File hddDir = Files.createTempDir();
    String hddPath = hddDir.getAbsolutePath();
    // Mock no write permission so worker storage paths cannot be initialize
    PowerMockito.mockStatic(DefaultStorageDir.class);
    Mockito.when(DefaultStorageDir.newStorageDir(ArgumentMatchers.any(DefaultStorageTier.class), ArgumentMatchers.anyInt(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenCallRealMethod();
    Mockito.when(DefaultStorageDir.newStorageDir(ArgumentMatchers.any(DefaultStorageTier.class), ArgumentMatchers.anyInt(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong(), ArgumentMatchers.startsWith(ssdPath), ArgumentMatchers.anyString())).thenThrow(new IOException("mock no write permission exception"));
    startClusterWithWorkerStorage(ssdPath, hddPath);
    FileUtils.deleteDirectory(hddDir);
    // Make sure lost storage is detected and reported to master
    Thread.sleep(10 * ServerConfiguration.getMs(PropertyKey.WORKER_BLOCK_HEARTBEAT_INTERVAL_MS));
    checkLostStorageResults(ssdPath, hddPath);
    mLocalAlluxioCluster.restartMasters();
    mLocalAlluxioCluster.waitForWorkersRegistered(6 * Constants.SECOND_MS);
    checkLostStorageResults(ssdPath, hddPath);
}
Also used : DefaultStorageTier(alluxio.worker.block.meta.DefaultStorageTier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IOException(java.io.IOException) File(java.io.File) PowerMockIgnore(org.powermock.core.classloader.annotations.PowerMockIgnore) Ignore(org.junit.Ignore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)1 DefaultStorageTier (alluxio.worker.block.meta.DefaultStorageTier)1 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Ignore (org.junit.Ignore)1 PowerMockIgnore (org.powermock.core.classloader.annotations.PowerMockIgnore)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1