-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SLING-12266 - Add support for repo snapshots (#39)
Allow resource resolver types to save the state of an already initialized repository and restore it when creating future repositories. Only Oak can meaningfully support this right now, as it's already built on immutable node state objects.
- Loading branch information
Showing
4 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
core/src/test/java/org/apache/sling/testing/mock/sling/MockSlingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.sling.testing.mock.sling; | ||
|
||
import org.apache.sling.api.resource.ResourceResolverFactory; | ||
import org.apache.sling.jcr.api.SlingRepository; | ||
import org.apache.sling.testing.mock.osgi.MockOsgi; | ||
import org.apache.sling.testing.mock.sling.spi.ResourceResolverTypeAdapter; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.junit.Test; | ||
import org.osgi.framework.BundleContext; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class MockSlingTest { | ||
|
||
private SlingRepository buildRepo(ResourceResolverTypeAdapter adapter) { | ||
BundleContext context = MockOsgi.newBundleContext(); | ||
MockSling.buildFactoryFromRepository(NodeTypeMode.NOT_SUPPORTED, context, adapter); | ||
return context.getService(context.getServiceReference(SlingRepository.class)); | ||
} | ||
|
||
@Test | ||
public void testAdapterDoesNotSupportSnapshots() { | ||
ResourceResolverTypeAdapter snapshotUnawareAdapter = new ResourceResolverTypeAdapter() { | ||
@Override | ||
public @Nullable ResourceResolverFactory newResourceResolverFactory() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public SlingRepository newSlingRepository() { | ||
return new MockJcrSlingRepository(); | ||
} | ||
}; | ||
|
||
SlingRepository repo1 = buildRepo(snapshotUnawareAdapter); | ||
SlingRepository repo2 = buildRepo(snapshotUnawareAdapter); | ||
|
||
assertNotNull(repo1); | ||
assertNotNull(repo2); | ||
assertNotSame(repo2, repo1); | ||
} | ||
|
||
@Test | ||
public void testAdapterSupportsSnapshots() { | ||
SlingRepository freshRepo = new MockJcrSlingRepository(); | ||
SlingRepository snapshotRepo = new MockJcrSlingRepository(); | ||
ResourceResolverTypeAdapter snapshotAwareAdapter = new ResourceResolverTypeAdapter() { | ||
@Override | ||
public @Nullable ResourceResolverFactory newResourceResolverFactory() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public SlingRepository newSlingRepository() { | ||
return freshRepo; | ||
} | ||
|
||
@Override | ||
public Object snapshot(SlingRepository repository) { | ||
return "dummy"; | ||
} | ||
|
||
@Override | ||
public SlingRepository newSlingRepositoryFromSnapshot(Object snapshot) { | ||
return snapshotRepo; | ||
} | ||
}; | ||
|
||
SlingRepository repo1 = buildRepo(snapshotAwareAdapter); | ||
SlingRepository repo2 = buildRepo(snapshotAwareAdapter); | ||
|
||
assertSame(freshRepo, repo1); | ||
assertSame(snapshotRepo, repo2); | ||
} | ||
} |