org.apache.hadoop.crypto.key.kms.ValueQueue.SyncGenerationPolicy Java Examples

The following examples show how to use org.apache.hadoop.crypto.key.kms.ValueQueue.SyncGenerationPolicy. 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 File: TestValueQueue.java    From hadoop with 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 File: EagerKeyGeneratorKeyProviderCryptoExtension.java    From ranger with Apache License 2.0 6 votes vote down vote up
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 #3
Source File: EagerKeyGeneratorKeyProviderCryptoExtension.java    From big-c with Apache License 2.0 6 votes vote down vote up
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 #4
Source File: TestValueQueue.java    From big-c with 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 #5
Source File: TestValueQueue.java    From big-c with 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 #6
Source File: TestValueQueue.java    From big-c with 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 #7
Source File: EagerKeyGeneratorKeyProviderCryptoExtension.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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 #8
Source File: TestValueQueue.java    From hadoop with 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 #9
Source File: TestValueQueue.java    From hadoop with 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 #10
Source File: TestValueQueue.java    From hadoop with 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 #11
Source File: TestValueQueue.java    From big-c with 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 #12
Source File: TestValueQueue.java    From hadoop with 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 #13
Source File: TestValueQueue.java    From big-c with 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 #14
Source File: TestValueQueue.java    From big-c with 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 #15
Source File: TestValueQueue.java    From big-c with 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 #16
Source File: TestValueQueue.java    From hadoop with 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 #17
Source File: TestValueQueue.java    From big-c with 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 #18
Source File: TestValueQueue.java    From hadoop with 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 #19
Source File: TestValueQueue.java    From hadoop with 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();
}