@Test
  public void testAddPartitionSpecPartDuplicateInSpec() throws Exception {

    createTable();
    List<Partition> partitions = buildPartitions(DB_NAME, TABLE_NAME,
        Lists.newArrayList("2014", "2015", "2017", "2017", "2018", "2019"));
    PartitionSpecProxy partitionSpecProxy =
        buildPartitionSpec(DB_NAME, TABLE_NAME, null, partitions);
    try {
      client.add_partitions_pspec(partitionSpecProxy);
      Assert.fail("MetaException should have happened.");
    } catch (MetaException e) {
      // Expected exception
    }

    List<Partition> parts = client.listPartitions(DB_NAME, TABLE_NAME, MAX);
    Assert.assertNotNull(parts);
    Assert.assertTrue(parts.isEmpty());
    for (Partition partition : partitions) {
      Assert.assertFalse(metaStore.isPathExists(new Path(partition.getSd().getLocation())));
    }
  }
Tests for creating partitions from partition spec.
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestAddPartitionsFromPartSpec.java