@Test public void testToThrift() throws DestroyFailedException { // verify thrift serialization Credentials creds = new Credentials("test", new PasswordToken("testing")); TCredentials tCreds = creds.toThrift(new MockInstance()); assertEquals("test", tCreds.getPrincipal()); assertEquals(PasswordToken.class.getName(), tCreds.getTokenClassName()); assertArrayEquals( AuthenticationTokenSerializer.serialize(new PasswordToken("testing")), tCreds.getToken()); // verify that we can't serialize if it's destroyed creds.getToken().destroy(); try { creds.toThrift(new MockInstance()); fail(); } catch (Exception e) { assertTrue(e instanceof RuntimeException); assertTrue(e.getCause() instanceof AccumuloSecurityException); assertTrue( AccumuloSecurityException.class .cast(e.getCause()) .getSecurityErrorCode() .equals(SecurityErrorCode.TOKEN_EXPIRED)); } }