DatastoreStore extends StoreBase { @Override public void save(Session session) throws IOException { log.debug("Persisting session: " + session.getId()); if (!(session instanceof DatastoreSession)) { throw new IOException( "The session must be an instance of DatastoreSession to be serialized"); } DatastoreSession datastoreSession = (DatastoreSession) session; Key sessionKey = newKey(session.getId()); KeyFactory attributeKeyFactory = datastore.newKeyFactory() .setKind(sessionKind) .addAncestor(PathElement.of(sessionKind, sessionKey.getName())); List<Entity> entities = serializeSession(datastoreSession, sessionKey, attributeKeyFactory); TraceContext datastoreSaveContext = startSpan("Storing the session in the Datastore"); datastore.put(entities.toArray(new FullEntity[0])); datastore.delete(datastoreSession.getSuppressedAttributes().stream() .map(attributeKeyFactory::newKey) .toArray(Key[]::new)); endSpan(datastoreSaveContext); }  @Override int getSize(); @Override String[] keys(); @Override Session load(String id); @Override void remove(String id); @Override void clear(); @Override void save(Session session); @Override void processExpires(); void setNamespace(String namespace); void setSessionKind(String sessionKind); void setTraceRequest(boolean traceRequest);  }
@Test public void testSessionSave() throws Exception { DatastoreSession session = spy(new DatastoreSession(manager)); session.setValid(true); session.setId(keyId); session.setAttribute("count", 5); store.save(session); ArgumentCaptor captor = ArgumentCaptor.forClass(Entity.class); verify(datastore).put((FullEntity<?>[]) captor.capture()); verify(session).saveAttributesToEntity(any()); List<Entity> entities = captor.getAllValues(); assertEquals(2, entities.size()); assertTrue(entities.stream() .map(e -> e.getKey().getName()) .collect(Collectors.toList()) .containsAll(Arrays.asList("count", keyId))); }