Created
January 22, 2014 22:41
-
-
Save jprante/8568886 to your computer and use it in GitHub Desktop.
Measuring alias get time
This file contains 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.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; | |
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; | |
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; | |
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; | |
import org.elasticsearch.client.Client; | |
import org.elasticsearch.client.transport.NoNodeAvailableException; | |
import org.elasticsearch.cluster.block.ClusterBlockException; | |
import org.elasticsearch.cluster.metadata.AliasAction; | |
import org.elasticsearch.common.Strings; | |
import org.elasticsearch.common.logging.ESLogger; | |
import org.elasticsearch.common.logging.ESLoggerFactory; | |
import org.elasticsearch.common.settings.ImmutableSettings; | |
import org.elasticsearch.common.settings.Settings; | |
import org.elasticsearch.indices.IndexMissingException; | |
import org.elasticsearch.node.Node; | |
import org.testng.annotations.Test; | |
import static org.elasticsearch.node.NodeBuilder.nodeBuilder; | |
public class AliasTest { | |
private static final ESLogger logger = ESLoggerFactory.getLogger(AliasTest.class.getName()); | |
@Test | |
public void testAlias() { | |
Node node = null; | |
try { | |
Settings settings = ImmutableSettings.settingsBuilder() | |
.put("cluster.name", "test") | |
.put("gateway.type", "none") | |
.build(); | |
node = nodeBuilder().settings(settings).local(true).node(); | |
Client client = node.client(); | |
// create index | |
CreateIndexRequest indexRequest = new CreateIndexRequest("test"); | |
client.admin().indices().create(indexRequest).actionGet(); | |
// put alias | |
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest(); | |
String[] indices = new String[]{"test"}; | |
String[] aliases = new String[]{"test_alias"}; | |
IndicesAliasesRequest.AliasActions aliasAction = new IndicesAliasesRequest.AliasActions(AliasAction.Type.ADD, indices, aliases); | |
indicesAliasesRequest.addAliasAction(aliasAction); | |
client.admin().indices().aliases(indicesAliasesRequest).actionGet(); | |
// get alias | |
GetAliasesRequest getAliasesRequest = new GetAliasesRequest(Strings.EMPTY_ARRAY); | |
long t0 = System.nanoTime(); | |
GetAliasesResponse getAliasesResponse = client.admin().indices().getAliases(getAliasesRequest).actionGet(); | |
long t1 = System.nanoTime() - t0; | |
logger.info("{} time(ms) = {}", getAliasesResponse.getAliases(), t1 / 1000000); | |
} catch (ClusterBlockException | NoNodeAvailableException | IndexMissingException e) { | |
logger.warn(e.getMessage()); | |
} finally { | |
if (node !=null){ | |
node.stop(); | |
node.close(); | |
} | |
} | |
} | |
} |
This file contains 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
------------------------------------------------------- | |
T E S T S | |
------------------------------------------------------- | |
Running AliasTest | |
Configuring TestNG with: TestNG652Configurator | |
[23:39:10,958][INFO ][org.elasticsearch.node ] [Morlun] version[1.0.0.RC1], pid[27536], build[c6155c5/2014-01-15T17:02:32Z] | |
[23:39:10,959][INFO ][org.elasticsearch.node ] [Morlun] initializing ... | |
[23:39:10,971][INFO ][org.elasticsearch.plugins] [Morlun] loaded [], sites [] | |
[23:39:13,242][INFO ][org.elasticsearch.node ] [Morlun] initialized | |
[23:39:13,242][INFO ][org.elasticsearch.node ] [Morlun] starting ... | |
[23:39:13,250][INFO ][org.elasticsearch.transport] [Morlun] bound_address {local[1]}, publish_address {local[1]} | |
[23:39:13,267][INFO ][org.elasticsearch.cluster.service] [Morlun] new_master [Morlun][aZlNinRwStapkSShgz1Rpg][Jorg-Prantes-MacBook-Pro.local][local[1]]{local=true}, reason: local-disco-initial_connect(master) | |
[23:39:13,275][INFO ][org.elasticsearch.discovery] [Morlun] test/aZlNinRwStapkSShgz1Rpg | |
[23:39:13,315][INFO ][org.elasticsearch.gateway] [Morlun] recovered [0] indices into cluster_state | |
[23:39:13,415][INFO ][org.elasticsearch.http ] [Morlun] bound_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish_address {inet[/192.168.1.113:9200]} | |
[23:39:13,420][INFO ][org.elasticsearch.node ] [Morlun] started | |
[23:39:13,869][INFO ][org.elasticsearch.cluster.metadata] [Morlun] [test] creating index, cause [api], shards [5]/[1], mappings [] | |
[23:39:14,235][INFO ][AliasTest ] [test=>[org.elasticsearch.cluster.metadata.AliasMetaData@1c08f8bd]] time(ms) = 15 | |
[23:39:14,236][INFO ][org.elasticsearch.node ] [Morlun] stopping ... | |
[23:39:14,288][INFO ][org.elasticsearch.node ] [Morlun] stopped | |
[23:39:14,289][INFO ][org.elasticsearch.node ] [Morlun] closing ... | |
[23:39:14,303][INFO ][org.elasticsearch.node ] [Morlun] closed | |
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.142 sec - in AliasTest | |
testAlias(AliasTest) Time elapsed: 3.589 sec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment