java/core/src/test/org/apache/orc/TestInMemoryKeystore.java
@Test
  public void testMultipleVersion() throws IOException {
    Assert.assertEquals(0,
        memoryKeystore.getCurrentKeyVersion("key256").getVersion());
    memoryKeystore.addKey("key256", 1, EncryptionAlgorithm.AES_256, "NewSecret".getBytes());
    Assert.assertEquals(1,
        memoryKeystore.getCurrentKeyVersion("key256").getVersion());

    try {
      memoryKeystore.addKey("key256", 1, EncryptionAlgorithm.AES_256,
          "BadSecret".getBytes());
      Assert.fail("Keys with smaller version should not be added.");
    } catch (final IOException e) {
      Assert.assertTrue(e.toString().contains("equal or higher version"));
    }

    memoryKeystore.addKey("key256", 2, EncryptionAlgorithm.AES_256,
        "NewerSecret".getBytes());
    Assert.assertEquals(2,
        memoryKeystore.getCurrentKeyVersion("key256").getVersion());

    // make sure that all 3 versions of key256 exist and have different secrets
    Key key0 = memoryKeystore.getLocalKey(memoryKeystore.getKeyVersion("key256", 0, null), new byte[16]);
    Key key1 = memoryKeystore.getLocalKey(memoryKeystore.getKeyVersion("key256", 1, null), new byte[16]);
    Key key2 = memoryKeystore.getLocalKey(memoryKeystore.getKeyVersion("key256", 2, null), new byte[16]);
    Assert.assertNotEquals(new BytesWritable(key0.getEncoded()).toString(),
        new BytesWritable(key1.getEncoded()).toString());
    Assert.assertNotEquals(new BytesWritable(key1.getEncoded()).toString(),
        new BytesWritable(key2.getEncoded()).toString());
  }
/**
   * This will test:
   * 1. Scenario where key with smaller version then existing should not be allowed
   * 2. Test multiple versions of the key
   * 3. Test get current version
   *
   * @throws IOException
   */
This will test:
1. Scenario where key with smaller version then existing should not be allowed
2. Test multiple versions of the key
3. Test get current version


This will test : 1 . Scenario where key with smaller version then existing should not be allowed 2 . Test multiple versions of the key 3 . Test get current version
@Test
  public void testMultipleVersion() throws IOException {
    Assert.assertEquals(0,
        memoryKeystore.getCurrentKeyVersion("key256").getVersion());
    memoryKeystore.addKey("key256", 1, EncryptionAlgorithm.AES_256, "NewSecret".getBytes());
    Assert.assertEquals(1,
        memoryKeystore.getCurrentKeyVersion("key256").getVersion());
    try {
      memoryKeystore.addKey("key256", 1, EncryptionAlgorithm.AES_256,
          "BadSecret".getBytes());
      Assert.fail("Keys with smaller version should not be added.");
    } catch (final IOException e) {
      Assert.assertTrue(e.toString().contains("equal or higher version"));
    }
    memoryKeystore.addKey("key256", 2, EncryptionAlgorithm.AES_256,
        "NewerSecret".getBytes());
    Assert.assertEquals(2,
        memoryKeystore.getCurrentKeyVersion("key256").getVersion());
    Key key0 = memoryKeystore.getLocalKey(memoryKeystore.getKeyVersion("key256", 0, null), new byte[16]);
    Key key1 = memoryKeystore.getLocalKey(memoryKeystore.getKeyVersion("key256", 1, null), new byte[16]);
    Key key2 = memoryKeystore.getLocalKey(memoryKeystore.getKeyVersion("key256", 2, null), new byte[16]);
    Assert.assertNotEquals(new BytesWritable(key0.getEncoded()).toString(),
        new BytesWritable(key1.getEncoded()).toString());
    Assert.assertNotEquals(new BytesWritable(key1.getEncoded()).toString(),
        new BytesWritable(key2.getEncoded()).toString());
  }
@ Test public void testMultipleVersion ( ) throws IOException { Assert . assertEquals ( 0 , memoryKeystore . getCurrentKeyVersion ( "key256" ) . getVersion ( ) ) ; memoryKeystore . addKey ( "key256" , 1 , EncryptionAlgorithm . AES_256 , "NewSecret" . getBytes ( ) ) ; Assert . assertEquals ( 1 , memoryKeystore . getCurrentKeyVersion ( "key256" ) . getVersion ( ) ) ; try { memoryKeystore . addKey ( "key256" , 1 , EncryptionAlgorithm . AES_256 , "BadSecret" . getBytes ( ) ) ; Assert . fail ( "Keys with smaller version should not be added." ) ; } catch ( final IOException e ) { Assert . assertTrue ( e . toString ( ) . contains ( "equal or higher version" ) ) ; } memoryKeystore . addKey ( "key256" , 2 , EncryptionAlgorithm . AES_256 , "NewerSecret" . getBytes ( ) ) ; Assert . assertEquals ( 2 , memoryKeystore . getCurrentKeyVersion ( "key256" ) . getVersion ( ) ) ; Key key0 = memoryKeystore . getLocalKey ( memoryKeystore . getKeyVersion ( "key256" , 0 , null ) , new byte [ 16 ] ) ; Key key1 = memoryKeystore . getLocalKey ( memoryKeystore . getKeyVersion ( "key256" , 1 , null ) , new byte [ 16 ] ) ; Key key2 = memoryKeystore . getLocalKey ( memoryKeystore . getKeyVersion ( "key256" , 2 , null ) , new byte [ 16 ] ) ; Assert . assertNotEquals ( new BytesWritable ( key0 . getEncoded ( ) ) . toString ( ) , new BytesWritable ( key1 . getEncoded ( ) ) . toString ( ) ) ; Assert . assertNotEquals ( new BytesWritable ( key1 . getEncoded ( ) ) . toString ( ) , new BytesWritable ( key2 . getEncoded ( ) ) . toString ( ) ) ; }
This will test:
 1.
This will test : 1 .
// make sure that all 3 versions of key256 exist and have different secrets