Search in sources :

Example 1 with DeploymentArtifact

use of com.oracle.bedrock.runtime.remote.DeploymentArtifact in project oracle-bedrock by coherence-community.

the class CurlHttpDeployerTest method shouldDeployEmptyArtifacts.

@Test
public void shouldDeployEmptyArtifacts() throws Exception {
    Map<String, DeploymentArtifact> artifacts = new HashMap<>();
    String destination = "/foo";
    Platform platform = mock(Platform.class);
    InetSocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), 1234);
    OptionsByType optionsByType = OptionsByType.empty();
    CurlHttpDeployer deploymentMethod = new CurlHttpDeployer();
    DeployedArtifacts deployedArtifacts = new DeployedArtifacts();
    deploymentMethod.deployAllArtifacts(artifacts, destination, platform, address, optionsByType, deployedArtifacts);
    verifyNoMoreInteractions(platform);
}
Also used : LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) Platform(com.oracle.bedrock.runtime.Platform) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) DeployedArtifacts(com.oracle.bedrock.runtime.remote.DeployedArtifacts) DeploymentArtifact(com.oracle.bedrock.runtime.remote.DeploymentArtifact) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 2 with DeploymentArtifact

use of com.oracle.bedrock.runtime.remote.DeploymentArtifact in project oracle-bedrock by coherence-community.

the class AbstractHttpDeployerTest method createArtifactList.

/**
 * Create a given number of random binary artifacts.
 *
 * @return a {@link List} containing the specified number
 *         of {@link DeploymentArtifact}s
 */
public List<DeploymentArtifact> createArtifactList(int count) throws Exception {
    List<DeploymentArtifact> artifacts = new ArrayList<>();
    Random random = new Random(System.currentTimeMillis());
    File root = temporaryFolder.newFolder();
    for (int i = 0; i < count; i++) {
        File file = new File(root, "File-" + i + ".bin");
        int size = random.nextInt(1000) * 100;
        try (FileOutputStream stream = new FileOutputStream(file)) {
            for (int b = 0; b < size; b++) {
                stream.write(random.nextInt());
            }
        }
        artifacts.add(new DeploymentArtifact(file));
    }
    return artifacts;
}
Also used : Random(java.util.Random) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) DeploymentArtifact(com.oracle.bedrock.runtime.remote.DeploymentArtifact) File(java.io.File)

Example 3 with DeploymentArtifact

use of com.oracle.bedrock.runtime.remote.DeploymentArtifact in project oracle-bedrock by coherence-community.

the class AbstractHttpDeployerTest method createArtifactMap.

/**
 * Create a given number of random binary artifacts returned in a
 * {@link Map} keyed on the encoded URL path of the artifacts
 * source file name.
 *
 * @return a {@link Map} containing the specified number
 *         of {@link DeploymentArtifact}s keyed on the
 *         encoded URL path of the artifacts source file name
 */
public Map<String, DeploymentArtifact> createArtifactMap(int count) throws Exception {
    Map<String, DeploymentArtifact> artifacts = new LinkedHashMap<>();
    for (DeploymentArtifact artifact : createArtifactList(count)) {
        String urlPath = "/" + URLEncoder.encode(artifact.getSourceFile().getCanonicalPath(), "UTF-8");
        artifacts.put(urlPath, artifact);
    }
    return artifacts;
}
Also used : DeploymentArtifact(com.oracle.bedrock.runtime.remote.DeploymentArtifact) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with DeploymentArtifact

use of com.oracle.bedrock.runtime.remote.DeploymentArtifact in project oracle-bedrock by coherence-community.

the class HttpDeployerTest method shouldHandleRequestForNonExistentArtifact.

@Test
public void shouldHandleRequestForNonExistentArtifact() throws Exception {
    Map<String, DeploymentArtifact> artifacts = createArtifactMap(1);
    HttpExchange exchange = mock(HttpExchange.class);
    HttpDeployer.ArtifactsHandler handler = new HttpDeployer.ArtifactsHandler(artifacts);
    URI uri = new File("/foo.txt").toURI();
    when(exchange.getRequestURI()).thenReturn(uri);
    handler.handle(exchange);
    verify(exchange).sendResponseHeaders(404, 0);
}
Also used : HttpExchange(com.sun.net.httpserver.HttpExchange) DeploymentArtifact(com.oracle.bedrock.runtime.remote.DeploymentArtifact) URI(java.net.URI) File(java.io.File) Test(org.junit.Test)

Example 5 with DeploymentArtifact

use of com.oracle.bedrock.runtime.remote.DeploymentArtifact in project oracle-bedrock by coherence-community.

the class JSchFileShareDeployerTest method shouldDeployArtifactWithDestination.

@Test
public void shouldDeployArtifactWithDestination() throws Exception {
    String content = "To fetch a pail of water";
    File file = createArtifact(content);
    File dest = temporaryFolder.newFolder();
    DeploymentArtifact artifact = new DeploymentArtifact(file, dest);
    List<DeploymentArtifact> list = Collections.singletonList(artifact);
    Deployer deployer = JSchFileShareDeployer.sshFileShareDeployer(localShare, remoteShare);
    deployer.deploy(list, workingDirectory, getRemotePlatform());
    File expected = new File(dest, file.getName());
    assertThat(expected.exists(), is(true));
    try (BufferedReader reader = new BufferedReader(new FileReader(expected))) {
        String line = reader.readLine();
        assertThat(line, is(content));
    }
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) DeploymentArtifact(com.oracle.bedrock.runtime.remote.DeploymentArtifact) Deployer(com.oracle.bedrock.runtime.remote.options.Deployer) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Aggregations

DeploymentArtifact (com.oracle.bedrock.runtime.remote.DeploymentArtifact)26 File (java.io.File)20 Test (org.junit.Test)17 Platform (com.oracle.bedrock.runtime.Platform)10 OptionsByType (com.oracle.bedrock.OptionsByType)9 ArrayList (java.util.ArrayList)7 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)6 DeployedArtifacts (com.oracle.bedrock.runtime.remote.DeployedArtifacts)6 BufferedReader (java.io.BufferedReader)4 FileReader (java.io.FileReader)4 LinkedHashMap (java.util.LinkedHashMap)4 Option (com.oracle.bedrock.Option)3 PlatformSeparators (com.oracle.bedrock.runtime.options.PlatformSeparators)3 AbstractRemoteTest (com.oracle.bedrock.runtime.remote.AbstractRemoteTest)3 RemotePlatform (com.oracle.bedrock.runtime.remote.RemotePlatform)3 Table (com.oracle.bedrock.table.Table)3 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 InetSocketAddress (java.net.InetSocketAddress)3 HashMap (java.util.HashMap)3