This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
CHROOT_PART="/dev/sda3" | |
CHROOT_DIR="/mnt/proxmox" | |
die() { echo "$*" 1>&2 ; exit 1; } | |
echo "Checking for debootstrap package" | |
pacman -Q debootstrap >/dev/null 2>&1 \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Test; | |
import org.mockito.ArgumentCaptor; | |
import org.mockito.Mockito; | |
import java.util.List; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import static org.junit.Assert.assertEquals; | |
import static org.mockito.Mockito.after; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public synchronized void start() { | |
try { | |
final DatagramSocket socket = new DatagramSocket(port); | |
thread = new UDPServerThread(socket, processor); | |
thread.start(); | |
} catch (SocketException e) { | |
LOGGER.error("Unable to start server.", e); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void revoke(String lockId) throws RemoteException { | |
revokes.add(lockId); | |
if (locks.containsKey(lockId) && locks.get(lockId).getState() == LockState.FREE) { | |
release(lockId); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LockIdentifier lock = revokes.take(); | |
OwnerId ownerId = lock.getOwnerId(); | |
LockCacheConnector lockCache = (LockCacheConnector) LocateRegistry.getRegistry( | |
ownerId.getAddress().getHostAddress(), ownerId.getPort() | |
).lookup(DefaultLockCache.BINDING_NAME); | |
lockCache.revoke(lock.getLockId()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sk.vsds.udp | |
import sk.vsds.udp.processor.MessageProcessor | |
import spock.lang.Specification | |
/** | |
* Tests {@link UDPServerThread}. | |
* | |
* @author Dominik Matta | |
* @since 1.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testAcquiringLockInNoneStateRemotelyLocked() throws Exception { | |
final ExecutorService executor = Executors.newFixedThreadPool(2); | |
final AtomicBoolean wasAcquired = new AtomicBoolean(false); | |
Mockito.when(lockServer.acquire("lock", OWNER_ID, 0)).then( | |
new Answer<Boolean>() { | |
@Override | |
public Boolean answer(InvocationOnMock invocation) throws Throwable { | |
return wasAcquired.getAndSet(true); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean acquire(String lockId, String ownerId, long sequence) throws RemoteException { | |
Lock lock = locks.computeIfAbsent(lockId, l -> new ReentrantLock()); | |
lock.lock(); | |
return true; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
registry = LocateRegistry.createRegistry(port); | |
Remote exported = UnicastRemoteObject.exportObject(this, port); | |
registry.rebind(BINDING_NAME, exported); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testLockAcquiring() throws Exception { | |
final AtomicBoolean released = new AtomicBoolean(false); | |
// acquire lock | |
Registry registry = LocateRegistry.getRegistry(REGISTRY_PORT); | |
LockServer remote = ((LockServer) registry.lookup(LockServer.BINDING_NAME)); | |
assertTrue(remote.acquire("lock", null, 0)); | |
// lock in new Thread, and when completed, assert that lock had been released |