Quick Start

更新时间:
复制 MD 格式

To test if your application runs correctly in specific environments, use PelicanDT to simulate abnormal conditions. These conditions include application stops, high CPU usage, high memory usage, network interruptions, and network latency. This topic demonstrates how to use PelicanDT by injecting a command into a server to query the current path.

Install the PelicanDT SDK

You can add the PelicanDT software development kit (SDK) to your project in two ways:

  • Download the SDK source package and add it to your working directory.
  • Add the following dependency to the pom.xml file in your Maven project.
<dependency>
    <groupId>com.alibaba.pelican</groupId>
    <artifactId>PelicanDT</artifactId>
    <version>1.0.9</version>
</dependency>
			

Inject a command

Execute the following code in your project to inject a command into a remote server. The command queries the current path.

Note Enter your ECS public IP address, username, and logon password in the code.
import com.alibaba.pelican.chaos.client.impl.RemoteCmdClient;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

/**
 * @author moyun@middleware
 */
@Slf4j
public class TestRemoteCmdClient {

    @Test
    public void testRemoteCmdClient() {
        // The public IP address of the ECS instance
        String ip = "";
        // The username for the ECS instance, typically root
        String userName = "";
        // The logon password for the ECS instance
        String password = "";

        // Create and initialize a RemoteCmdClient instance
        RemoteCmdClientConfig remoteCmdClientConfig = new RemoteCmdClientConfig();
        remoteCmdClientConfig.setIp(ip);
        remoteCmdClientConfig.setUserName(userName);
        remoteCmdClientConfig.setPassword(password);
        RemoteCmdClient client = new RemoteCmdClient(remoteCmdClientConfig);

        // Execute the pwd command
        RemoteCmdResult resultInfo = client.execCmdWithPTY(new RemoteCmd("pwd"));
        log.info(resultInfo.getStdInfo());
    }
}
			

Verify the results

After the program runs, the log output is as follows:

[root@iz2ze0kv2rqck9wpheu5vxz ~]$pwd
/root
[root@iz2ze0kv2rqck9wpheu5vxz ~]$export HISTFILE=/dev/null
[root@iz2ze0kv2rqck9wpheu5vxz ~]$exit
logout
			

The second line shows that the current directory is /root.