Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Change location of local lock to be consistent depth with other state…
Browse files Browse the repository at this point in the history
… objects (#1472)
  • Loading branch information
Bill Graham authored Oct 5, 2016
1 parent 85ab6cd commit 252919b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String getNodePath(String root, String topology) {
}

public String getNodePath(String root, String topology, String extraToken) {
return concatPath(getNodePath(root, topology), extraToken);
return getNodePath(root, String.format("%s__%s", topology, extraToken));
}

private static String concatPath(String basePath, String appendPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package com.twitter.heron.statemgr.localfs;

import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;

import com.google.common.util.concurrent.ListenableFuture;
Expand Down Expand Up @@ -52,18 +54,23 @@
public class LocalFileSystemStateManagerTest {

private static final String TOPOLOGY_NAME = "topologyName";
private static final String LOCK_NAME = "topologyName";
private static final String LOCK_NAME = "lockName";
private static final String ROOT_ADDR = "/";
private LocalFileSystemStateManager manager;

@Before
public void before() throws Exception {
manager = initMockManager(ROOT_ADDR, false);
}

private static LocalFileSystemStateManager initMockManager(String rootPath, boolean initTree) {
Config config = Config.newBuilder()
.put(Keys.stateManagerRootPath(), ROOT_ADDR)
.put(LocalFileSystemKeys.initializeFileTree(), false)
.put(Keys.stateManagerRootPath(), rootPath)
.put(LocalFileSystemKeys.initializeFileTree(), initTree)
.build();
manager = Mockito.spy(new LocalFileSystemStateManager());
LocalFileSystemStateManager manager = Mockito.spy(new LocalFileSystemStateManager());
manager.initialize(config);
return manager;
}

@After
Expand Down Expand Up @@ -202,7 +209,7 @@ public void testDeletePackingPlan() throws Exception {
@Test
public void testGetLock() throws Exception {
initMocks();
String expectedLockPath = String.format("//locks/%s/%s", TOPOLOGY_NAME, LOCK_NAME);
String expectedLockPath = String.format("//locks/%s__%s", TOPOLOGY_NAME, LOCK_NAME);
byte[] expectedContents = Thread.currentThread().getName().getBytes(Charset.defaultCharset());

Lock lock = manager.getLock(TOPOLOGY_NAME, LOCK_NAME);
Expand All @@ -214,9 +221,18 @@ public void testGetLock() throws Exception {
assertDeleteFile(expectedLockPath);
}

@Test
public void testGetFilesystemLock() throws Exception {
Path tempDir = Files.createTempDirectory("heron-testGetFilesystemLock");
LocalFileSystemStateManager fsBackedManager = initMockManager(tempDir.toString(), true);
Lock lock = fsBackedManager.getLock(TOPOLOGY_NAME, LOCK_NAME);
Assert.assertTrue("Failed to get lock", lock.tryLock(0, TimeUnit.MILLISECONDS));
lock.unlock();
}

@Test
public void testLockTaken() throws Exception {
String expectedLockPath = String.format("//locks/%s/%s", TOPOLOGY_NAME, LOCK_NAME);
String expectedLockPath = String.format("//locks/%s__%s", TOPOLOGY_NAME, LOCK_NAME);
byte[] expectedContents = Thread.currentThread().getName().getBytes(Charset.defaultCharset());

PowerMockito.spy(FileUtils.class);
Expand Down

0 comments on commit 252919b

Please sign in to comment.