public void testAddIndexLabelWithRepeatIndex()

in hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/IndexLabelCoreTest.java [822:1027]


    public void testAddIndexLabelWithRepeatIndex() {
        super.initPropertyKeys();
        SchemaManager schema = graph().schema();

        schema.vertexLabel("person")
              .properties("name", "age", "city", "weight")
              .create();
        // Repeat index tests for existed range index
        schema.indexLabel("personByAge").onV("person").range()
              .by("age").create();
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("personByAge1").onV("person").range()
                  .by("age").create();
        });
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("personByAge2").onV("person").secondary()
                  .by("age").create();
        });
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("personByAge3").onV("person").shard()
                  .by("age").create();
        });
        schema.indexLabel("personByAge4").onV("person").unique()
              .by("age").create();
        schema.getIndexLabel("personByAge");
        schema.getIndexLabel("personByAge4");

        // Repeat index tests for existed secondary index(number)
        schema.vertexLabel("person1")
              .properties("name", "age", "city", "weight")
              .create();
        schema.indexLabel("person1ByAge").onV("person1").secondary()
              .by("age").create();
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("person1ByAge1").onV("person1").secondary()
                  .by("age").create();
        });
        schema.indexLabel("person1ByAge2").onV("person1").shard()
              .by("age").create();
        schema.indexLabel("person1ByAge3").onV("person1").range()
              .by("age").create();
        schema.indexLabel("person1ByAge4").onV("person1").unique()
              .by("age").create();
        Assert.assertThrows(NotFoundException.class, () -> {
            schema.getIndexLabel("person1ByAge");
        });
        Assert.assertThrows(NotFoundException.class, () -> {
            schema.getIndexLabel("person1ByAge2");
        });
        schema.getIndexLabel("person1ByAge3");
        schema.getIndexLabel("person1ByAge4");
        // Repeat index tests for existed secondary index(string)
        schema.vertexLabel("person2")
              .properties("name", "age", "city", "weight")
              .create();
        schema.indexLabel("person2ByCity").onV("person2").secondary()
              .by("city").create();
        schema.indexLabel("person2ByCity1").onV("person2").search()
              .by("city").create();
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("person2ByCity2").onV("person2").secondary()
                  .by("city").create();
        });
        schema.indexLabel("person2ByCity3").onV("person2").unique()
              .by("city").create();
        schema.getIndexLabel("person2ByCity");
        schema.getIndexLabel("person2ByCity1");
        schema.getIndexLabel("person2ByCity3");

        // Repeat index tests for existed shard index
        schema.vertexLabel("person3")
              .properties("name", "age", "city", "weight")
              .create();
        schema.indexLabel("person3ByAge").onV("person3").shard()
              .by("age").create();
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("person3ByAge1").onV("person3").secondary()
                  .by("age").create();
        });
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("person3ByAge2").onV("person3").shard()
                  .by("age").create();
        });
        schema.indexLabel("person3ByAge3").onV("person3").range()
              .by("age").create();
        schema.indexLabel("person3ByAge4").onV("person3").unique()
              .by("age").create();
        Assert.assertThrows(NotFoundException.class, () -> {
            schema.getIndexLabel("person3ByAge");
        });
        schema.getIndexLabel("person3ByAge3");
        schema.getIndexLabel("person3ByAge4");

        // Repeat index tests for existed search index
        schema.vertexLabel("person4")
              .properties("name", "age", "city", "weight")
              .create();
        schema.indexLabel("person4ByCity").onV("person4").search()
              .by("city").create();
        schema.indexLabel("person4ByCity1").onV("person4").secondary()
              .by("city").create();
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("person4ByCity2").onV("person4").search()
                  .by("city").create();
        });
        schema.indexLabel("person4ByCity3").onV("person4").unique()
              .by("city").create();
        schema.getIndexLabel("person4ByCity");
        schema.getIndexLabel("person4ByCity1");
        schema.getIndexLabel("person4ByCity3");

        // Repeat index tests for existed composite secondary index
        schema.vertexLabel("person5")
              .properties("name", "age", "city", "weight")
              .create();
        schema.indexLabel("person5ByCityAndName").onV("person5").secondary()
              .by("city", "name").create();
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("person5ByCity1").onV("person5").secondary()
                  .by("city").create();
        });
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("person5ByCity2").onV("person5").shard()
                  .by("city").create();
        });
        schema.indexLabel("person5ByCity3").onV("person5").search()
              .by("city").create();
        schema.indexLabel("person5ByCity4").onV("person5").unique()
              .by("city").create();
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("person5ByCityAndName1").onV("person5")
                  .secondary().by("city", "name").create();
        });
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("person5ByCityAndName2").onV("person5").shard()
                  .by("city", "name").create();
        });
        schema.getIndexLabel("person5ByCity3");
        schema.getIndexLabel("person5ByCity4");
        schema.indexLabel("person5ByCity4").remove();
        schema.indexLabel("person5ByCityAndName3").onV("person5").unique()
              .by("city", "name").create();
        schema.getIndexLabel("person5ByCityAndName3");

        // Repeat index tests for existed composite shard index
        schema.vertexLabel("person6")
              .properties("name", "age", "city", "weight")
              .create();
        schema.indexLabel("person6ByCityAndName").onV("person6").shard()
              .by("city", "name").create();
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("person6ByCity1").onV("person6").secondary()
                  .by("city").create();
        });
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("person6ByCity2").onV("person6").shard()
                  .by("city").create();
        });
        schema.indexLabel("person6ByCity3").onV("person6").search()
              .by("city").create();
        schema.indexLabel("person6ByCity4").onV("person6").unique()
              .by("city").create();
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("person6ByCityAndName1").onV("person6")
                  .secondary().by("city", "name").create();
        });
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("person6ByCityAndName2").onV("person6").shard()
                  .by("city").create();
        });
        schema.getIndexLabel("person6ByCity3");
        schema.getIndexLabel("person6ByCity4");
        schema.indexLabel("person6ByCity4").remove();
        schema.indexLabel("person6ByCityAndName3").onV("person6").unique()
              .by("city", "name").create();
        schema.getIndexLabel("person6ByCityAndName3");

        // Repeat index tests for existed unique index
        schema.vertexLabel("person7")
              .properties("name", "age", "city", "weight")
              .create();
        schema.indexLabel("person7ByCity").onV("person7").unique()
              .by("city").create();
        schema.indexLabel("person7ByCity1").onV("person7").secondary()
              .by("city").create();
        schema.indexLabel("person7ByCity1").remove();
        schema.indexLabel("person7ByCity2").onV("person7").shard()
              .by("city").create();
        schema.indexLabel("person7ByCity3").onV("person7").search()
              .by("city").create();
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("person7ByCity4").onV("person7").unique()
                  .by("city").create();
        });
        schema.indexLabel("person7ByCityAndName1").onV("person7")
              .secondary().by("city", "name").create();
        schema.indexLabel("person7ByCityAndName1").remove();
        schema.indexLabel("person7ByCityAndName2").onV("person7").shard()
              .by("city", "name").create();
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            schema.indexLabel("person7ByCityAndName3").onV("person7")
                  .unique().by("city", "name").create();
        });
        schema.getIndexLabel("person5ByCity3");
        schema.getIndexLabel("person7ByCityAndName2");
    }