@Test public void testUnSupportedResourceType() { XAStore.Provider provider = new XAStore.Provider(); @SuppressWarnings("unchecked") Store.Configuration<Object, Object> configuration = mock(Store.Configuration.class); ResourcePools resourcePools = mock(ResourcePools.class); Set<ResourceType<?>> resourceTypes = Collections.singleton(new TestResourceType()); when(configuration.getResourcePools()).thenReturn(resourcePools); when(resourcePools.getResourceTypeSet()).thenReturn(resourceTypes); try { provider.createStore(configuration, (ServiceConfiguration<?>) null); fail("IllegalStateException expected"); } catch (IllegalStateException e) { } }
XAStore.Provider provider = new XAStore.Provider(); provider.start(serviceProvider);
@Test public void testXAStoreProviderFailsToRankWhenNoTMProviderConfigured() throws Exception { XAStore.Provider provider = new XAStore.Provider(); provider.start(new ServiceProvider<Service>() { @Override public <U extends Service> U getService(Class<U> serviceType) { return null; } @Override public <U extends Service> Collection<U> getServicesOfType(Class<U> serviceType) { return emptySet(); } }); try { provider.wrapperStoreRank(Collections.singleton(mock(XAStoreConfiguration.class))); fail("Expected exception"); } catch (IllegalStateException e) { assertThat(e.getMessage(), containsString("TransactionManagerProvider")); } }
@Override public XAStore.Provider create(ServiceCreationConfiguration<XAStore.Provider> configuration) { return new XAStore.Provider(); }
@Test public void testRank() throws Exception { XAStore.Provider provider = new XAStore.Provider(); XAStoreConfiguration configuration = new XAStoreConfiguration("testXAResourceId"); ServiceLocator serviceLocator = dependencySet() .with(provider) .with(Store.Provider.class) .with(mock(DiskResourceService.class)) .with(mock(TransactionManagerProvider.class)).build(); serviceLocator.startAllServices(); Set<ServiceConfiguration<?>> xaStoreConfigs = Collections.singleton(configuration); assertThat(provider.wrapperStoreRank(xaStoreConfigs), is(1)); Set<ServiceConfiguration<?>> emptyConfigs = emptySet(); assertThat(provider.wrapperStoreRank(emptyConfigs), is(0)); }
@Override public XAStore.Provider create(ServiceCreationConfiguration<XAStore.Provider> configuration) { return new XAStore.Provider(); }