小编nat*_*bbs的帖子

JUnit Rule TemporaryFolder任意抛出IOException

我在这里遇到一个奇怪的问题......

我有一个JUnit实现了一些测试.该类如下所示:

public class MyTest {

    @Rule
    public TemporaryFolder folder = new TemporaryFolder();

    @Test
    public void myTest1() throws IOException {
        String destinationPath = folder.newFile("destination1.txt").getPath();
        // Do things
    }

    @Test
    public void myTest2() throws IOException {
        String destinationPath = folder.newFile("destination2.txt").getPath();
        // Do things
    }

    @Test
    public void myTest3() throws IOException {
        String destinationPath = folder.newFile("destination.txt").getPath();
        // Do things
    }
}
Run Code Online (Sandbox Code Playgroud)

这个测试类曾经在我之前的环境中工作,但仍然在Continuum中工作.

然而,当从Eclipse启动时,没有,部分或全部测试任意抛出IOException如下:

java.io.IOException: The system cannot find the path specified
    at java.io.WinNTFileSystem.createFileExclusively(Native Method)
    at java.io.File.createNewFile(File.java:883)
    at org.junit.rules.TemporaryFolder.newFile(TemporaryFolder.java:53)
    at MyTest.myTest2(MyTest.java:50) …
Run Code Online (Sandbox Code Playgroud)

java junit ioexception junit4

9
推荐指数
1
解决办法
1339
查看次数

具有资源属性 CloudFormation 的 UserData 脚本

主要问题:如何在云形成模板中引用依赖资源属性来构建用户数据脚本。

我尝试过的

  1. 方法在这里列出。
  2. 子函数的例子

我正在为三节点 Kafka 集群构建 CloudFormation 模板。

我在这里采用的方法是使用 EC2 实例上的 UserData 脚本在集群的每个节点上配置 Zookeeper 和 Kafka。

我使用SubBase64函数用PrimaryPrivateIpAddress我的 NetworkInterface填充我的用户数据脚本,但它们作为空字符串而不是实际值出现。我知道这些值被正确填充,因为它们是我在模板中输出的一部分。

我在下面包含了我的模板的资源块作为参考。为了简洁起见,我省略了一些无趣的部分。我还说明了我尝试过的几种不同的方法来解决 EC2 资源块不一致的问题。

EC2I8MWW:
  Type: 'AWS::EC2::Instance'
  DependsOn:
    - EC2NI2E8ES
    - EC2NI2PFST
    - EC2NI54B66
  Properties:
    KeyName: !Ref DesiredKeyName
    InstanceType: !Ref InstanceType
    NetworkInterfaces:
      - NetworkInterfaceId: !Ref EC2NI54B66
        DeviceIndex: "0"
    UserData:
      Fn::Base64:
        Fn::Sub:
          - |
            #!/bin/bash
            CONF="/etc/zookeeper/conf.dist/zoo.cfg"
            PRIVATE_1=${Private1}
            PRIVATE_2=${Private2}
            PRIVATE_3=${Private3}
            echo "# Zookeeper configuration for Talentreef" > "$CONF"
            cat <<EOT >> "$CONF"
            maxClientCnxns=50 …
Run Code Online (Sandbox Code Playgroud)

yaml amazon-ec2 amazon-web-services aws-cloudformation

6
推荐指数
1
解决办法
6312
查看次数