java copy directorytodirectory 替换,Java FileUtils.copyDirectoryToDirectory方法代码示例

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类

@Test

public void should_execute_sync_event_callback() throws Throwable {

// given: copy exist git to workspace

ClassLoader classLoader = TestBase.class.getClassLoader();

URL resource = classLoader.getResource("hello.git");

File path = new File(resource.getFile());

FileUtils.copyDirectoryToDirectory(path, gitWorkspace.toFile());

// and: register agent to sync service

AgentPath agent = agents.get(0);

syncService.load();

syncService.register(agent);

Assert.assertEquals(1, syncService.get(agent).queueSize());

// when: execute sync task

syncService.syncTask();

// then: the create session cmd should be send

CountMatchingStrategy strategy = new CountMatchingStrategy(CountMatchingStrategy.EQUAL_TO, 1);

verify(strategy, postRequestedFor(urlEqualTo("/cmd/queue/send?priority=10&retry=5")));

// when: mock create session cmd been callback

Cmd mockSessionCallback = new Cmd(agent.getZone(), agent.getName(), CmdType.CREATE_SESSION, null);

mockSessionCallback.setStatus(CmdStatus.SENT);

mockSessionCallback.setSessionId(createSessionCmdResponse.getSessionId());

syncService.onCallback(mockSessionCallback);

// then: send run shell cmd for sync event and sync task queue size not changed

strategy = new CountMatchingStrategy(CountMatchingStrategy.EQUAL_TO, 1);

verify(strategy, postRequestedFor(urlEqualTo("/cmd/send")));

Assert.assertEquals(2, syncService.getSyncTask(agent).getSyncQueue().size());

// when: mock cmd been executed

Cmd mockRunShellSuccess = new Cmd(agent.getZone(), agent.getName(), CmdType.RUN_SHELL, "git pull xxx");

mockRunShellSuccess.setSessionId(mockSessionCallback.getSessionId());

mockRunShellSuccess.setStatus(CmdStatus.LOGGED);

mockRunShellSuccess.setCmdResult(new CmdResult(0));

syncService.onCallback(mockRunShellSuccess);

// then: should send list repos cmd and sync task queue size should be 1

strategy = new CountMatchingStrategy(CountMatchingStrategy.EQUAL_TO, 2);

verify(strategy, postRequestedFor(urlEqualTo("/cmd/send")));

Assert.assertEquals(1, syncService.getSyncTask(agent).getSyncQueue().size());

// when: mock list cmd been executed

Cmd mockListRepoSuccess =

new Cmd(agent.getZone(), agent.getName(), CmdType.RUN_SHELL, "export FLOW_SYNC_LIST=$(ls)");

mockListRepoSuccess.setSessionId(mockSessionCallback.getSessionId());

mockListRepoSuccess.setStatus(CmdStatus.LOGGED);

mockListRepoSuccess.setCmdResult(new CmdResult(0));

mockListRepoSuccess.getCmdResult().getOutput().put(SyncEvent.FLOW_SYNC_LIST, "A[v1]\nB[v2]");

syncService.onCallback(mockListRepoSuccess);

// then: agent repo list size should be 2

Assert.assertEquals(2, syncService.get(agent).getRepos().size());

Assert.assertTrue(syncService.get(agent).getRepos().contains(new SyncRepo("A", "v1")));

Assert.assertTrue(syncService.get(agent).getRepos().contains(new SyncRepo("B", "v2")));

// then: should send delete session cmd and sync task queue size should be zero

strategy = new CountMatchingStrategy(CountMatchingStrategy.EQUAL_TO, 3);

verify(strategy, postRequestedFor(urlEqualTo("/cmd/send")));

Assert.assertEquals(0, syncService.getSyncTask(agent).getSyncQueue().size());

// when: mock delete session cmd

Cmd mockDeleteSession = new Cmd(agent.getZone(), agent.getName(), CmdType.DELETE_SESSION, null);

mockDeleteSession.setSessionId(mockRunShellSuccess.getSessionId());

mockDeleteSession.setStatus(CmdStatus.SENT);

syncService.onCallback(mockDeleteSession);

// then: sync task of agent should be deleted

Assert.assertNull(syncService.getSyncTask(agent));

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值