package com.github.terma.gigaspacesqlconsole.provider;

import com.github.terma.gigaspacesqlconsole.core.CountsRequest;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;

public class AdminCacheTest {

    @Test
    public void shouldCloseExpiredAdmins() throws InterruptedException {
        // given
        final AdminCache adminCache = new AdminCache(0);
        final CountsRequest countsRequest = new CountsRequest();

        countsRequest.url = "/./admin-cache-test";
        adminCache.createOrGet(countsRequest);

        countsRequest.url = "/./admin-cache-test1";
        countsRequest.user = "admin";
        adminCache.createOrGet(countsRequest);

        assertThat(adminCache.size(), equalTo(2));

        // when
        Thread.sleep(TimeUnit.SECONDS.toMillis(1));
        adminCache.clearExpired();

        // then
        assertThat(adminCache.size(), equalTo(0));
    }

}

@@ -990,10 +990,594 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void shouldNotCloseNotExpiredAdmin() throws InterruptedException %7B%0A        // given%0A        final AdminCache adminCache = new AdminCache(TimeUnit.MINUTES.toMillis(1));%0A        final CountsRequest countsRequest = new CountsRequest();%0A%0A        countsRequest.url = %22/./admin-cache-test%22;%0A        adminCache.createOrGet(countsRequest);%0A%0A        assertThat(adminCache.size(), equalTo(1));%0A%0A        // when%0A        Thread.sleep(TimeUnit.SECONDS.toMillis(1));%0A        adminCache.clearExpired();%0A%0A        // then%0A        assertThat(adminCache.size(), equalTo(1));%0A    %7D%0A%0A
 %7D%0A

Add more tests