@Test
  public void testAddPartitionSpecOneInvalid() throws Exception {

    createTable();
    String tableLocation = metaStore.getWarehouseRoot() + "/" + TABLE_NAME;
    Partition partition1 =
        buildPartition(DB_NAME, TABLE_NAME, "2016", tableLocation + "/year=2016");
    Partition partition2 =
        buildPartition(DB_NAME, TABLE_NAME, "2017", tableLocation + "/year=2017");
    Partition partition3 =
        buildPartition(Lists.newArrayList("2015", "march"), getYearAndMonthPartCols(), 1);
    partition3.getSd().setLocation(tableLocation + "/year=2015/month=march");
    Partition partition4 =
        buildPartition(DB_NAME, TABLE_NAME, "2018", tableLocation + "/year=2018");
    Partition partition5 =
        buildPartition(DB_NAME, TABLE_NAME, "2019", tableLocation + "/year=2019");
    List<Partition> partitions =
        Lists.newArrayList(partition1, partition2, partition3, partition4, partition5);
    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 part : partitions) {
      Assert.assertFalse(metaStore.isPathExists(new Path(part.getSd().getLocation())));
    }
  }
Tests for creating partitions from partition spec.
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestAddPartitionsFromPartSpec.java