summaryrefslogtreecommitdiffstats
path: root/configserver/src/test/java/com/yahoo/vespa/config/server/session/RemoteSessionRepoTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'configserver/src/test/java/com/yahoo/vespa/config/server/session/RemoteSessionRepoTest.java')
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/RemoteSessionRepoTest.java71
1 files changed, 39 insertions, 32 deletions
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/RemoteSessionRepoTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/RemoteSessionRepoTest.java
index 462062ce8a8..878339bd703 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/RemoteSessionRepoTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/RemoteSessionRepoTest.java
@@ -2,18 +2,22 @@
package com.yahoo.vespa.config.server.session;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.TenantName;
import com.yahoo.path.Path;
import com.yahoo.text.Utf8;
import com.yahoo.transaction.Transaction;
-import com.yahoo.vespa.config.server.*;
+import com.yahoo.vespa.config.server.TestComponentRegistry;
+import com.yahoo.vespa.config.server.TestWithCurator;
import com.yahoo.vespa.config.server.application.TenantApplications;
import com.yahoo.vespa.config.server.tenant.Tenant;
import com.yahoo.vespa.config.server.tenant.TenantBuilder;
+import com.yahoo.vespa.config.server.tenant.Tenants;
import com.yahoo.vespa.curator.Curator;
import org.junit.Before;
import org.junit.Test;
@@ -27,33 +31,35 @@ import java.util.concurrent.TimeUnit;
import java.util.function.LongPredicate;
/**
- * @author lulf
+ * @author Ulf Lilleengen
* @since 5.1
*/
public class RemoteSessionRepoTest extends TestWithCurator {
+ private static final TenantName tenantName = TenantName.defaultName();
+
private RemoteSessionRepo remoteSessionRepo;
@Before
public void setupFacade() throws Exception {
- createSession(2l, false);
- createSession(3l, false);
- curator.create(Path.fromString("/applications"));
- curator.create(Path.fromString("/sessions"));
- Tenant tenant = TenantBuilder.create(new TestComponentRegistry.Builder().curator(curator).build(),
- TenantName.defaultName(),
- Path.createRoot()).build();
+ Tenant tenant = TenantBuilder.create(new TestComponentRegistry.Builder()
+ .curator(curator)
+ .build(),
+ tenantName)
+ .build();
this.remoteSessionRepo = tenant.getRemoteSessionRepo();
+ curator.create(Tenants.getTenantPath(tenantName).append("/applications"));
+ curator.create(Tenants.getSessionsPath(tenantName));
+ createSession(1l, false);
+ createSession(2l, false);
}
private void createSession(long sessionId, boolean wait) {
- createSession("", sessionId, wait);
+ createSession(sessionId, wait, tenantName);
}
-
- private void createSession(String root, long sessionId, boolean wait) {
- Path sessionsPath = Path.fromString(root).append("sessions");
- curator.create(sessionsPath);
+ private void createSession(long sessionId, boolean wait, TenantName tenantName) {
+ Path sessionsPath = Tenants.getSessionsPath(tenantName);
SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator, sessionsPath.append(String.valueOf(sessionId)));
zkc.createNewSession(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
if (wait) {
@@ -64,27 +70,28 @@ public class RemoteSessionRepoTest extends TestWithCurator {
@Test
public void testInitialize() {
+ assertSessionExists(1l);
assertSessionExists(2l);
- assertSessionExists(3l);
}
@Test
public void testCreateSession() throws Exception {
- createSession(0l, true);
- assertSessionExists(0l);
+ createSession(3l, true);
+ assertSessionExists(3l);
}
@Test
public void testSessionStateChange() throws Exception {
- Path session = Path.fromString("/sessions/0");
- createSession(0l, true);
- assertSessionStatus(0l, Session.Status.NEW);
- assertStatusChange(0l, Session.Status.PREPARE);
- assertStatusChange(0l, Session.Status.ACTIVATE);
+ long sessionId = 3L;
+ createSession(sessionId, true);
+ assertSessionStatus(sessionId, Session.Status.NEW);
+ assertStatusChange(sessionId, Session.Status.PREPARE);
+ assertStatusChange(sessionId, Session.Status.ACTIVATE);
+ Path session = Tenants.getSessionsPath(tenantName).append("" + sessionId);
curator.delete(session);
- assertSessionRemoved(0l);
- assertNull(remoteSessionRepo.getSession(0l));
+ assertSessionRemoved(sessionId);
+ assertNull(remoteSessionRepo.getSession(sessionId));
}
// If reading a session throws an exception it should be handled and not prevent other applications
@@ -93,25 +100,25 @@ public class RemoteSessionRepoTest extends TestWithCurator {
// throw an exception).
@Test
public void testBadApplicationRepoOnActivate() throws Exception {
+ long sessionId = 3L;
TenantApplications applicationRepo = new FailingTenantApplications();
- curator.framework().create().forPath("/mytenant");
- Tenant tenant = TenantBuilder.create(new TestComponentRegistry.Builder().curator(curator).build(),
- TenantName.from("mytenant"),
- Path.fromString("mytenant"))
+ TenantName mytenant = TenantName.from("mytenant");
+ Tenant tenant = TenantBuilder.create(new TestComponentRegistry.Builder().curator(curator).build(), mytenant)
.withApplicationRepo(applicationRepo)
.build();
+ curator.create(Tenants.getSessionsPath(mytenant));
remoteSessionRepo = tenant.getRemoteSessionRepo();
assertThat(remoteSessionRepo.listSessions().size(), is(0));
- createSession("/mytenant", 2l, true);
+ createSession(sessionId, true, mytenant);
assertThat(remoteSessionRepo.listSessions().size(), is(1));
}
private void assertStatusChange(long sessionId, Session.Status status) throws Exception {
- Path statePath = Path.fromString("/sessions/" + sessionId).append(ConfigCurator.SESSIONSTATE_ZK_SUBPATH);
+ Path statePath = Tenants.getSessionsPath(tenantName).append("" + sessionId).append(ConfigCurator.SESSIONSTATE_ZK_SUBPATH);
curator.create(statePath);
curatorFramework.setData().forPath(statePath.getAbsolute(), Utf8.toBytes(status.toString()));
System.out.println("Setting status " + status + " for " + sessionId);
- assertSessionStatus(0l, status);
+ assertSessionStatus(sessionId, status);
}
private void assertSessionRemoved(long sessionId) {