Java Code Examples for org.apache.hadoop.crypto.key.kms.ValueQueue

The following examples show how to use org.apache.hadoop.crypto.key.kms.ValueQueue. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hadoop   Source File: TestValueQueue.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that Queue is initialized (Warmed-up) for provided keys
 */
@Test
public void testWarmUp() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.5f, 300, 1,
          SyncGenerationPolicy.ALL, filler);
  vq.initializeQueuesForKeys("k1", "k2", "k3");
  FillInfo[] fillInfos =
    {filler.getTop(), filler.getTop(), filler.getTop()};
  Assert.assertEquals(5, fillInfos[0].num);
  Assert.assertEquals(5, fillInfos[1].num);
  Assert.assertEquals(5, fillInfos[2].num);
  Assert.assertEquals(Sets.newHashSet("k1", "k2", "k3"),
      Sets.newHashSet(fillInfos[0].key,
          fillInfos[1].key,
          fillInfos[2].key));
  vq.shutdown();
}
 
Example 2
Source Project: hadoop   Source File: TestValueQueue.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verify getAtMost when SyncGeneration Policy = ALL
 */
@Test
public void testgetAtMostPolicyALL() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.1f, 300, 1,
          SyncGenerationPolicy.ALL, filler);
  Assert.assertEquals("test", vq.getNext("k1"));
  Assert.assertEquals(1, filler.getTop().num);
  // Drain completely
  Assert.assertEquals(10, vq.getAtMost("k1", 10).size());
  // Synchronous call
  Assert.assertEquals(10, filler.getTop().num);
  // Ask for more... return all
  Assert.assertEquals(19, vq.getAtMost("k1", 19).size());
  // Synchronous call (No Async call since num > lowWatermark)
  Assert.assertEquals(19, filler.getTop().num);
  vq.shutdown();
}
 
Example 3
Source Project: hadoop   Source File: TestValueQueue.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verify getAtMost when SyncGeneration Policy = LOW_WATERMARK
 */
@Test
public void testgetAtMostPolicyLOW_WATERMARK() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.3f, 300, 1,
          SyncGenerationPolicy.LOW_WATERMARK, filler);
  Assert.assertEquals("test", vq.getNext("k1"));
  Assert.assertEquals(3, filler.getTop().num);
  // Drain completely
  Assert.assertEquals(3, vq.getAtMost("k1", 10).size());
  // Synchronous call
  Assert.assertEquals(1, filler.getTop().num);
  // Asynch Refill call
  Assert.assertEquals(10, filler.getTop().num);
  vq.shutdown();
}
 
Example 4
public CryptoExtension(Configuration conf,
    KeyProviderCryptoExtension keyProviderCryptoExtension) {
  this.keyProviderCryptoExtension = keyProviderCryptoExtension;
  encKeyVersionQueue =
      new ValueQueue<KeyProviderCryptoExtension.EncryptedKeyVersion>(
          conf.getInt(KMS_KEY_CACHE_SIZE,
              KMS_KEY_CACHE_SIZE_DEFAULT),
          conf.getFloat(KMS_KEY_CACHE_LOW_WATERMARK,
              KMS_KEY_CACHE_LOW_WATERMARK_DEFAULT),
          conf.getInt(KMS_KEY_CACHE_EXPIRY_MS,
              KMS_KEY_CACHE_EXPIRY_DEFAULT),
          conf.getInt(KMS_KEY_CACHE_NUM_REFILL_THREADS,
              KMS_KEY_CACHE_NUM_REFILL_THREADS_DEFAULT),
          SyncGenerationPolicy.LOW_WATERMARK, new EncryptedQueueRefiller()
      );
}
 
Example 5
Source Project: big-c   Source File: TestValueQueue.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that Queue is initialized (Warmed-up) for provided keys
 */
@Test
public void testWarmUp() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.5f, 300, 1,
          SyncGenerationPolicy.ALL, filler);
  vq.initializeQueuesForKeys("k1", "k2", "k3");
  FillInfo[] fillInfos =
    {filler.getTop(), filler.getTop(), filler.getTop()};
  Assert.assertEquals(5, fillInfos[0].num);
  Assert.assertEquals(5, fillInfos[1].num);
  Assert.assertEquals(5, fillInfos[2].num);
  Assert.assertEquals(Sets.newHashSet("k1", "k2", "k3"),
      Sets.newHashSet(fillInfos[0].key,
          fillInfos[1].key,
          fillInfos[2].key));
  vq.shutdown();
}
 
Example 6
Source Project: big-c   Source File: TestValueQueue.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verify getAtMost when SyncGeneration Policy = ALL
 */
@Test
public void testgetAtMostPolicyALL() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.1f, 300, 1,
          SyncGenerationPolicy.ALL, filler);
  Assert.assertEquals("test", vq.getNext("k1"));
  Assert.assertEquals(1, filler.getTop().num);
  // Drain completely
  Assert.assertEquals(10, vq.getAtMost("k1", 10).size());
  // Synchronous call
  Assert.assertEquals(10, filler.getTop().num);
  // Ask for more... return all
  Assert.assertEquals(19, vq.getAtMost("k1", 19).size());
  // Synchronous call (No Async call since num > lowWatermark)
  Assert.assertEquals(19, filler.getTop().num);
  vq.shutdown();
}
 
Example 7
Source Project: big-c   Source File: TestValueQueue.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verify getAtMost when SyncGeneration Policy = LOW_WATERMARK
 */
@Test
public void testgetAtMostPolicyLOW_WATERMARK() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.3f, 300, 1,
          SyncGenerationPolicy.LOW_WATERMARK, filler);
  Assert.assertEquals("test", vq.getNext("k1"));
  Assert.assertEquals(3, filler.getTop().num);
  // Drain completely
  Assert.assertEquals(3, vq.getAtMost("k1", 10).size());
  // Synchronous call
  Assert.assertEquals(1, filler.getTop().num);
  // Asynch Refill call
  Assert.assertEquals(10, filler.getTop().num);
  vq.shutdown();
}
 
Example 8
public CryptoExtension(Configuration conf,
    KeyProviderCryptoExtension keyProviderCryptoExtension) {
  this.keyProviderCryptoExtension = keyProviderCryptoExtension;
  encKeyVersionQueue =
      new ValueQueue<KeyProviderCryptoExtension.EncryptedKeyVersion>(
          conf.getInt(KMS_KEY_CACHE_SIZE,
              KMS_KEY_CACHE_SIZE_DEFAULT),
          conf.getFloat(KMS_KEY_CACHE_LOW_WATERMARK,
              KMS_KEY_CACHE_LOW_WATERMARK_DEFAULT),
          conf.getInt(KMS_KEY_CACHE_EXPIRY_MS,
              KMS_KEY_CACHE_EXPIRY_DEFAULT),
          conf.getInt(KMS_KEY_CACHE_NUM_REFILL_THREADS,
              KMS_KEY_CACHE_NUM_REFILL_THREADS_DEFAULT),
          SyncGenerationPolicy.LOW_WATERMARK, new EncryptedQueueRefiller()
      );
}
 
Example 9
public CryptoExtension(Configuration conf,
    KeyProviderCryptoExtension keyProviderCryptoExtension) {
  this.keyProviderCryptoExtension = keyProviderCryptoExtension;
  encKeyVersionQueue =
      new ValueQueue<KeyProviderCryptoExtension.EncryptedKeyVersion>(
          conf.getInt(KMS_KEY_CACHE_SIZE,
              KMS_KEY_CACHE_SIZE_DEFAULT),
          conf.getFloat(KMS_KEY_CACHE_LOW_WATERMARK,
              KMS_KEY_CACHE_LOW_WATERMARK_DEFAULT),
          conf.getInt(KMS_KEY_CACHE_EXPIRY_MS,
              KMS_KEY_CACHE_EXPIRY_DEFAULT),
          conf.getInt(KMS_KEY_CACHE_NUM_REFILL_THREADS,
              KMS_KEY_CACHE_NUM_REFILL_THREADS_DEFAULT),
          SyncGenerationPolicy.LOW_WATERMARK, new EncryptedQueueRefiller()
      );
}
 
Example 10
Source Project: hadoop   Source File: TestValueQueue.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that Queue is initially filled to "numInitValues"
 */
@Test
public void testInitFill() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.1f, 300, 1,
          SyncGenerationPolicy.ALL, filler);
  Assert.assertEquals("test", vq.getNext("k1"));
  Assert.assertEquals(1, filler.getTop().num);
  vq.shutdown();
}
 
Example 11
Source Project: hadoop   Source File: TestValueQueue.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that the refill task is executed after "checkInterval" if
 * num values below "lowWatermark"
 */
@Test
public void testRefill() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.1f, 300, 1,
          SyncGenerationPolicy.ALL, filler);
  Assert.assertEquals("test", vq.getNext("k1"));
  Assert.assertEquals(1, filler.getTop().num);
  // Trigger refill
  vq.getNext("k1");
  Assert.assertEquals(1, filler.getTop().num);
  Assert.assertEquals(10, filler.getTop().num);
  vq.shutdown();
}
 
Example 12
Source Project: hadoop   Source File: TestValueQueue.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that the No refill Happens after "checkInterval" if
 * num values above "lowWatermark"
 */
@Test
public void testNoRefill() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.5f, 300, 1,
          SyncGenerationPolicy.ALL, filler);
  Assert.assertEquals("test", vq.getNext("k1"));
  Assert.assertEquals(5, filler.getTop().num);
  Assert.assertEquals(null, filler.getTop());
  vq.shutdown();
}
 
Example 13
Source Project: hadoop   Source File: TestValueQueue.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Verify getAtMost when SyncGeneration Policy = ALL
 */
@Test
public void testgetAtMostPolicyATLEAST_ONE() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.3f, 300, 1,
          SyncGenerationPolicy.ATLEAST_ONE, filler);
  Assert.assertEquals("test", vq.getNext("k1"));
  Assert.assertEquals(3, filler.getTop().num);
  // Drain completely
  Assert.assertEquals(2, vq.getAtMost("k1", 10).size());
  // Asynch Refill call
  Assert.assertEquals(10, filler.getTop().num);
  vq.shutdown();
}
 
Example 14
Source Project: hadoop   Source File: TestValueQueue.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDrain() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.1f, 300, 1,
          SyncGenerationPolicy.ALL, filler);
  Assert.assertEquals("test", vq.getNext("k1"));
  Assert.assertEquals(1, filler.getTop().num);
  vq.drain("k1");
  Assert.assertNull(filler.getTop());
  vq.shutdown();
}
 
Example 15
Source Project: big-c   Source File: TestValueQueue.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that Queue is initially filled to "numInitValues"
 */
@Test
public void testInitFill() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.1f, 300, 1,
          SyncGenerationPolicy.ALL, filler);
  Assert.assertEquals("test", vq.getNext("k1"));
  Assert.assertEquals(1, filler.getTop().num);
  vq.shutdown();
}
 
Example 16
Source Project: big-c   Source File: TestValueQueue.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that the refill task is executed after "checkInterval" if
 * num values below "lowWatermark"
 */
@Test
public void testRefill() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.1f, 300, 1,
          SyncGenerationPolicy.ALL, filler);
  Assert.assertEquals("test", vq.getNext("k1"));
  Assert.assertEquals(1, filler.getTop().num);
  // Trigger refill
  vq.getNext("k1");
  Assert.assertEquals(1, filler.getTop().num);
  Assert.assertEquals(10, filler.getTop().num);
  vq.shutdown();
}
 
Example 17
Source Project: big-c   Source File: TestValueQueue.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that the No refill Happens after "checkInterval" if
 * num values above "lowWatermark"
 */
@Test
public void testNoRefill() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.5f, 300, 1,
          SyncGenerationPolicy.ALL, filler);
  Assert.assertEquals("test", vq.getNext("k1"));
  Assert.assertEquals(5, filler.getTop().num);
  Assert.assertEquals(null, filler.getTop());
  vq.shutdown();
}
 
Example 18
Source Project: big-c   Source File: TestValueQueue.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Verify getAtMost when SyncGeneration Policy = ALL
 */
@Test
public void testgetAtMostPolicyATLEAST_ONE() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.3f, 300, 1,
          SyncGenerationPolicy.ATLEAST_ONE, filler);
  Assert.assertEquals("test", vq.getNext("k1"));
  Assert.assertEquals(3, filler.getTop().num);
  // Drain completely
  Assert.assertEquals(2, vq.getAtMost("k1", 10).size());
  // Asynch Refill call
  Assert.assertEquals(10, filler.getTop().num);
  vq.shutdown();
}
 
Example 19
Source Project: big-c   Source File: TestValueQueue.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDrain() throws Exception {
  MockFiller filler = new MockFiller();
  ValueQueue<String> vq =
      new ValueQueue<String>(10, 0.1f, 300, 1,
          SyncGenerationPolicy.ALL, filler);
  Assert.assertEquals("test", vq.getNext("k1"));
  Assert.assertEquals(1, filler.getTop().num);
  vq.drain("k1");
  Assert.assertNull(filler.getTop());
  vq.shutdown();
}