Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -832,12 +832,13 @@ public static int[] findFreePorts(int nb) throws IOException
sockets[i] = bindFreePort();
ports[i] = sockets[i].getLocalPort();
}
close(sockets);
return ports;
}
finally
{

// Close them all, including when an allocation failed halfway: a socket which stays bound
// holds its port in listen state, and bindFreePort() hands out each number only once.
close(sockets);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import org.opends.server.types.SearchResultEntry;
import org.opends.server.util.StaticUtils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -172,8 +173,6 @@ public void setUp() throws Exception
{
super.setUp();

replServerPort = findFreePort();

// Create base dns for each tested modes
addEntry("dn: " + SAFE_DATA_DN,
"objectClass: top",
Expand All @@ -186,6 +185,19 @@ public void setUp() throws Exception
"objectClass: organizationalUnit");
}

/**
* Allocates the listen port of the fake replication server, for one invocation only: each of them
* starts a fake replication server again, and a port which is bound again and again is exposed,
* for the whole time it is not bound, to anything in this JVM which may take it in the meantime.
* Both the fake replication server and the domain configuration entry which points at it are
* created by the test method itself, hence after this.
*/
@BeforeMethod
public void findReplicationServerPort() throws IOException
{
replServerPort = findFreePort();
}

/** Add an entry in the database. */
private void addEntry(String... ldifLines) throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import org.opends.server.types.Attributes;
import org.opends.server.types.Entry;
import org.opends.server.types.Modification;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -129,18 +128,6 @@ private void debugInfo(String s) {
}
}

/**
* Before starting the tests configure some stuff
*/
@BeforeClass
@Override
public void setUp() throws Exception
{
super.setUp();

replServerPort = findFreePort();
}

/** Returns a bunch of single values for fractional-exclude configuration attribute. */
@DataProvider
private Object[][] testExcludePrecommitProvider()
Expand Down Expand Up @@ -373,6 +360,10 @@ private void createFakeReplicationDomain(boolean firstBackend,

private void initTest() throws Exception
{
// Allocate the listen port of the replication server for this invocation only: a port which is
// bound again and again is exposed, for the whole time it is not bound, to anything in this JVM
// which may take it in the meantime.
replServerPort = findFreePort();
replicationDomain = null;
fractionalDomainCfgEntry = null;
replicationServer = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.opends.server.util.CollectionUtils.*;
import static org.testng.Assert.*;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
Expand Down Expand Up @@ -71,7 +72,6 @@
import org.opends.server.replication.service.ReplicationDomain;
import org.opends.server.types.DirectoryException;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -196,20 +196,15 @@ private void debugInfo(String s)
}
}

/**
* Before starting the tests configure some stuff.
*/
@BeforeClass
@Override
public void setUp() throws Exception
private void initTest() throws IOException
{
super.setUp();

/*
* Allocate the listen ports of the real replication servers for this invocation only. The test
* methods of this class run several hundred times, each of them creating a replication server
* again, and a port which is bound again and again is exposed, for the whole time it is not
* bound, to anything in this JVM which may take it in the meantime.
*/
rsPorts = TestCaseUtils.findFreePorts(4);
}

private void initTest()
{
fakeRDs = new FakeReplicationDomain[13];
fakeRs1 = fakeRs2 = fakeRs3 = null;
rs1 = rs2 = rs3 = rs4 = null;
Expand Down
Loading